Skip to content
Related Articles

Related Articles

Improve 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:

_.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 :