Lodash _.mod() Method

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 varmod  = _.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 varmod  = _.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 varmod  = _.mod( 12, 1 );     console.log("The Modulus is :", mod); | 
Output:
The Modulus is : 0
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, zambiatek Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
 
				 
					


