Lodash _.sub() 方法
Lodash _.sub() 方法返回所有给定参数的差异。
句法:
_.sub( val1, val2, ..., valn );
参数:该方法返回n个值来操作它们的_.sub()方法。
返回值:此方法返回所有给定参数的差异。
注意:这在普通 JavaScript 中不起作用,因为它需要安装 lodash.js contrib 库。 Lodash.js contrib 库可以使用npm install lodash-contrib –save 安装。
示例 1:
Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib');
var diff = _.sub( 10, 2, 4, 1 );
console.log("The Difference is : ", diff);
Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib');
var diff = _.sub( 10 );
console.log("The Difference is : ", diff);
Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib');
var diff = _.sub( 1, 3, 5, 7, 9, 99, 100 );
console.log("The Difference is : ", diff);
输出:
The Difference is : 3
示例 2:
Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib');
var diff = _.sub( 10 );
console.log("The Difference is : ", diff);
输出:
The Difference is : 10
示例 3:
Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib');
var diff = _.sub( 1, 3, 5, 7, 9, 99, 100 );
console.log("The Difference is : ", diff);
输出:
The Difference is : -222