HomeLanguagesJavascriptLodash _.mod() Method

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
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
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen 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!
RELATED ARTICLES

3 COMMENTS

Most Popular

Dominic
32533 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6913 POSTS0 COMMENTS
Nicole Veronica
12029 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12132 POSTS0 COMMENTS
Shaida Kate Naidoo
7043 POSTS0 COMMENTS
Ted Musemwa
7280 POSTS0 COMMENTS
Thapelo Manthata
7000 POSTS0 COMMENTS
Umr Jansen
6986 POSTS0 COMMENTS