Lodash _.falsey() 方法
Lodash _.falsey() 方法检查给定值是否为假,并返回相应的布尔值。假值是在布尔上下文中表示假的值。
句法:
_.falsey( value );
参数:此方法接受上面提到的单个参数,如下所述:
- value:要检查给定值的错误值。
返回值:如果给定值为 false,此方法返回布尔值 true,否则返回 false。
注意:这在普通 JavaScript 中不起作用,因为它需要安装 lodash.js contrib 库。 Lodash.js contrib 库可以使用npm install lodash-contrib 安装。
示例 1:
Javascript
// Defining underscore lodash variable
var _ = require('lodash-contrib');
var bool = _.falsey(false);
console.log("Given Value is Falsey : ", bool);
Javascript
// Defining underscore lodash variable
var _ = require('lodash-contrib');
var bool = _.falsey(10);
console.log("Given Value is Falsey : ", bool);
Javascript
// Defining underscore lodash variable
var _ = require('lodash-contrib');
var bool = _.falsey([ 1, 2, 3 ]);
console.log("Given Value is Falsey : ", bool);
var bool = _.falsey({});
console.log("Given Value is Falsey : ", bool);
Javascript
// Defining underscore lodash variable
var _ = require('lodash-contrib');
var bool = _.falsey(false);
console.log("Given Value is Falsey : ", bool);
var bool = _.falsey("false");
console.log("Given Value is Falsey : ", bool);
输出:
Given Value is Falsey : true
示例 2:
Javascript
// Defining underscore lodash variable
var _ = require('lodash-contrib');
var bool = _.falsey(10);
console.log("Given Value is Falsey : ", bool);
输出:
Given Value is Falsey : false
示例 3:
Javascript
// Defining underscore lodash variable
var _ = require('lodash-contrib');
var bool = _.falsey([ 1, 2, 3 ]);
console.log("Given Value is Falsey : ", bool);
var bool = _.falsey({});
console.log("Given Value is Falsey : ", bool);
输出:
Given Value is Falsey : false
Given Value is Falsey : false
示例 4:
Javascript
// Defining underscore lodash variable
var _ = require('lodash-contrib');
var bool = _.falsey(false);
console.log("Given Value is Falsey : ", bool);
var bool = _.falsey("false");
console.log("Given Value is Falsey : ", bool);
输出:
Given Value is Falsey : true
Given Value is Falsey : false