Lodash _.isNegative() 方法
Lodash _.isNegative() 方法检查给定值是否为负值并返回相应的布尔值。
句法:
_.isNegative( value );
参数:此方法采用单个参数,如上所述,如下所述:
- value:要检查负值的给定值。
返回值:如果给定值为 Negative,则此方法返回布尔值 true,否则返回 false。
注意:这在普通 JavaScript 中不起作用,因为它需要安装 lodash.js contrib 库。 Lodash.js contrib 库可以使用npm install lodash-contrib 安装。
示例 1:
Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib');
// Checking for _.isNegative() method
console.log("The Value is Negative : " + _.isNegative(-500));
console.log("The Value is Negative : " + _.isNegative(500));
console.log("The Value is Negative : " + _.isNegative('G'));
Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib');
// Checking for _.isNegative() method
console.log("The Value is Negative : " + _.isNegative(-10.5));
console.log("The Value is Negative : " + _.isNegative(10.5));
console.log("The Value is Negative : " + _.isNegative({}));
输出:
The Value is Negative : true
The Value is Negative : false
The Value is Negative : false
示例 2:
Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib');
// Checking for _.isNegative() method
console.log("The Value is Negative : " + _.isNegative(-10.5));
console.log("The Value is Negative : " + _.isNegative(10.5));
console.log("The Value is Negative : " + _.isNegative({}));
输出:
The Value is Negative : true
The Value is Negative : false
The Value is Negative : false