Lodash _.isPositive() 方法
Lodash _.isPositive() 方法检查给定值是否为正,并返回相应的布尔值。
句法:
_.isPositive(value);
参数:此方法接受如上所述和如下所述的单个参数:
- value:要检查的给定值是否为正值。
返回值:如果给定值为正,则此方法返回布尔值 true,否则返回 false。
注意:这在普通 JavaScript 中不起作用,因为它需要安装 lodash.js contrib 库。 Lodash.js contrib 库可以使用以下命令安装:
npm install lodash-contrib
示例 1:
// Defining underscore lodash variable
var _ = require('lodash-contrib');
// Checking for _.isPositive() method
console.log("The Value is Positive : " + _.isPositive(20));
输出:
The Value is Positive : true
示例 2:
// Defining underscore lodash variable
var _ = require('lodash-contrib');
// Checking for _.isPositive() method
console.log("The Value is Positive : " + _.isPositive(-1000));
console.log("The Value is Positive : " + _.isPositive("100"));
输出:
The Value is Positive : false
The Value is Positive : true
示例 3:
// Defining underscore lodash variable
var _ = require('lodash-contrib');
// Checking for _.isPositive() method
console.log("The Value is Positive : " + _.isPositive(true));
console.log("The Value is Positive : " + _.isPositive([10, 20]));
输出:
The Value is Positive : true
The Value is Positive : false