Thursday, September 4, 2025
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

Most Popular

Dominic
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6629 POSTS0 COMMENTS
Nicole Veronica
11799 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11858 POSTS0 COMMENTS
Shaida Kate Naidoo
6749 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6698 POSTS0 COMMENTS
Umr Jansen
6716 POSTS0 COMMENTS