Skip to content
Related Articles

Related Articles

Lodash _.subtract() Method

View Discussion
Improve Article
Save Article
Like Article
  • Last Updated : 05 Sep, 2020

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

The _.subtract() method is used to subtract two numbers.

Syntax:

_.subtract(minuend, subtrahend)

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

  • minuend: This parameter holds the first number in a subtraction.
  • subtrahend: This parameter holds the second number in a subtraction.

Return Value: This method returns the difference between two numbers.

Example 1: Here, const _ = require(‘lodash’) is used to import the lodash library into the file.

Javascript




// Requiring the lodash library  
const _ = require("lodash");  
    
// Use of _.subtract() method 
let gfg = _.subtract(50, 18); 
        
// Printing the output  
console.log(gfg);

Output:

32

Example 2:  

Javascript




// Requiring the lodash library  
const _ = require("lodash");  
    
// Use of _.subtract() method 
let gfg = _.subtract(87, -98); 
        
// Printing the output  
console.log(gfg);

Output:

185

Example 3:  

Javascript




// Requiring the lodash library  
const _ = require("lodash");  
    
// Use of _.subtract() method 
let gfg = _.subtract(-126, -53); 
        
// Printing the output  
console.log(gfg);

Output:

-73

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!