Open In App

Lodash _.mod() Method

Last Updated : 29 Sep, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc.

The _.mod() method is used to return the modulus of the given numbers, that is, the remainder of dividing the given dividend by the given divisor.

Syntax:

_.mod( dividend, divisor )

Parameters: This method takes two parameters as mentioned above and described below:

  • dividend: It is the dividend from which the modulus is calculated.
  • divisor: It is the 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 lodash contrib library to be installed. The Lodash contrib library can be installed using npm install lodash-contrib –save.

Example 1:

Javascript




// Defining lodash contrib variable 
var _ = require('lodash-contrib'); 
  
// Using the _.mod() method
var mod  = _.mod( 33, 5 ); 
    
console.log("The Modulus is :", mod);


Output:

The Modulus is : 3

Example 2:

Javascript




// Defining lodash contrib variable 
var _ = require('lodash-contrib'); 
  
// Using the _.mod() method
var mod  = _.mod( 170, 35 ); 
    
console.log("The Modulus is :", mod);


Output:

The Modulus is : 30

Example 3:

Javascript




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


Output:

The Modulus is : 0


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads