📜  Lodash _.not() 方法

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

Lodash _.not() 方法

Lodash _.not() 方法返回一个布尔值,它与给定值的真实性布尔值相反。

句法:

_.not( value );

参数:此方法采用一个参数,如上所述,如下所述:

  • value:返回相反布尔值的给定值。

返回值:此方法返回一个布尔值。

注意:这在普通 JavaScript 中不起作用,因为它需要安装 lodash.js contrib 库。 Lodash.js contrib 库可以使用npm install lodash-contrib –save 安装

示例 1:

Javascript
// Defining lodash contrib variable 
var _ = require('lodash-contrib'); 
  
var bool = _.not( true ); 
    
console.log("Opposite boolean value 'true' is : ", bool);
  
var bool = _.not( false ); 
    
console.log("Opposite boolean value 'false' is : ", bool);


Javascript
// Defining lodash contrib variable 
var _ = require('lodash-contrib'); 
  
var bool = _.not( 0 ); 
    
console.log("Opposite boolean value '0' is : ", bool);
  
var bool = _.not( 1 ); 
    
console.log("Opposite boolean value '1' is : ", bool);
  
var bool = _.not( 10 ); 
    
console.log("Opposite boolean value '10' is : ", bool);


Javascript
// Defining lodash contrib variable 
var _ = require('lodash-contrib'); 
  
var bool = _.not( {} ); 
    
console.log("Opposite boolean value empty object is : ", bool);
  
var bool = _.not( {'G' : "GeeksforGeeks"} ); 
    
console.log("Opposite boolean value object is : ", bool);
  
var bool = _.not( null ); 
    
console.log("Opposite boolean value 'null' is : ", bool);


输出:

Opposite boolean value 'true' is : false
Opposite boolean value 'false' is : true

示例 2:

Javascript

// Defining lodash contrib variable 
var _ = require('lodash-contrib'); 
  
var bool = _.not( 0 ); 
    
console.log("Opposite boolean value '0' is : ", bool);
  
var bool = _.not( 1 ); 
    
console.log("Opposite boolean value '1' is : ", bool);
  
var bool = _.not( 10 ); 
    
console.log("Opposite boolean value '10' is : ", bool);

输出:

Opposite boolean value '0' is : true
Opposite boolean value '1' is : false
Opposite boolean value '10' is : false

示例 3:

Javascript

// Defining lodash contrib variable 
var _ = require('lodash-contrib'); 
  
var bool = _.not( {} ); 
    
console.log("Opposite boolean value empty object is : ", bool);
  
var bool = _.not( {'G' : "GeeksforGeeks"} ); 
    
console.log("Opposite boolean value object is : ", bool);
  
var bool = _.not( null ); 
    
console.log("Opposite boolean value 'null' is : ", bool);

输出:

Opposite boolean value empty object is : false
Opposite boolean value object is : false
Opposite boolean value 'null' is : true