Lodash _.inc() 方法
Lodash _.inc() 方法通过将给定值加 1 来返回结果。
句法:
_.inc( value );
参数:此方法接受一个值并使用 _.inc() 方法将其递增。
返回值:此方法通过将给定值加 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 = 100
var incrVal = _.inc( val );
console.log("The Given value is :", val);
console.log("The Increment of Given value is :", incrVal);
Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib');
var val = 51
var incrVal = _.inc( val );
console.log("The Given value is :",val);
console.log("The Increment of Given value is :",incrVal);
输出:
The Given value is : 100
The Increment of Given value is : 101
示例 2:
Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib');
var val = 51
var incrVal = _.inc( val );
console.log("The Given value is :",val);
console.log("The Increment of Given value is :",incrVal);
输出:
The Given value is : 51
The Increment of Given value is : 52