Lodash _.dec() 方法
Lodash _.dec() 方法通过将给定值减 1 来返回结果。
句法:
_.dec( value );
参数:此方法接受一个值并递减它们。
返回值:此方法通过将给定值减 1 来返回结果。
注意:这在普通 JavaScript 中不起作用,因为它需要安装 lodash.js contrib 库。 Lodash.js contrib 库可以使用npm install lodash-contrib –save 安装。
示例 1:
Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib');
var val = 33
var decrVal = _.dec( val );
console.log("The Given value is :", val);
console.log("The Decrement of Given value is :", decrVal);
Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib');
var val = 100
var decrVal = _.dec( val );
console.log("The Given value is :", val);
console.log("The Decrement of Given value is :", decrVal);
输出:
The Given value is : 33
The Decrement of Given value is : 32
示例 2:
Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib');
var val = 100
var decrVal = _.dec( val );
console.log("The Given value is :", val);
console.log("The Decrement of Given value is :", decrVal);
输出:
The Given value is : 100
The Decrement of Given value is : 99