📜  Underscore.js _.dec() 方法

📅  最后修改于: 2022-05-13 01:56:20.887000             🧑  作者: Mango

Underscore.js _.dec() 方法

这 _。 dec () 方法 r通过将给定值减1 来返回结果

句法:

_.dec( 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 = 33
var decrVal  = _.dec( val );
  
console.log("The Given value is :", val);
console.log("The Decrement of Given value is :", decrVal);


Javascript
// Defining underscore contrib variable
var _ = require('underscore-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 underscore contrib variable
var _ = require('underscore-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