Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

Underscore.js | _.mod() Method

  • Last Updated : 05 Aug, 2020

The _.mod() Method returns the remainder of dividing the given dividend by the given divisor.

Syntax:

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

_.mod( dividend, divisor );

Parameters:

  • dividend: given dividend from which mod is calculated.
  • divisor: given divisor which is used to calculate the modulus.

Return Value: This method returns the calculated modulus from the given arguments.



Note: This will not work in normal JavaScript because it requires the underscore.js contrib library to be installed.

underscore.js contrib library can be installed using npm install underscore-contrib –save.

Example 1:




// Defining underscore contrib variable
var _ = require('underscore-contrib'); 
  
var mod  = _.mod( 24, 5 );
  
console.log("The Modulus is :", mod);

Output:

The Modulus is : 4

Example 2:




// Defining underscore contrib variable
var _ = require('underscore-contrib'); 
  
var mod  = _.mod( 120, 25 );
  
console.log("The Modulus is :", mod);

Output:

The Modulus is : 20

Example 3:




// Defining underscore contrib variable
var _ = require('underscore-contrib'); 
  
var mod  = _.mod( 12, 1 );
  
console.log("The Modulus is :", mod);

Output:

The Modulus is : 0



My Personal Notes arrow_drop_up
Recommended Articles
Page :