Underscore.js _.inc() 方法
这 _。 inc () 方法 r通过将给定值增加1 来返回结果。
句法:
_.inc( value );
参数:此方法接受一个值并递增它们。
返回值:此方法通过将给定值增加1 来返回结果。
注意:这在普通 JavaScript 中不起作用,因为它需要安装 underscore.js contrib 库。
underscore.js contrib 库可以使用npm install underscore-contrib –save 安装。
示例 1:
Javascript
// Defining underscore contrib variable
var _ = require('underscore-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 underscore contrib variable
var _ = require('underscore-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 underscore contrib variable
var _ = require('underscore-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