📜  Underscore.js _.neq() 方法

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

Underscore.js _.neq() 方法

_.neq()方法使用松散不等式 (!=) 检查每个参数是否不等于前一个参数。因此,相应地返回一个布尔值。

句法:

_.neq( val1, val2, ..., valn );

参数:此方法需要 n 个值对其进行操作。

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

注意:这在普通 JavaScript 中不起作用,因为它需要安装 underscore.js contrib 库。

underscore.js contrib 库可以使用npm install underscore-contrib –save 安装。

示例 1:

// Defining underscore contrib variable
var _ = require('underscore-contrib'); 
  
var neq  = _.neq( 3, 1 );
  
console.log("Each arguments are not equal to previous one :", neq);

输出:

Each arguments are not equal to previous one : true

示例 2:

// Defining underscore contrib variable
var _ = require('underscore-contrib'); 
  
var neq  = _.neq( 4, 4 );
  
console.log("Each arguments are not equal to previous one :", neq);

输出:

Each arguments are not equal to previous one : false

示例 3:

// Defining underscore contrib variable
var _ = require('underscore-contrib'); 
  
var neq  = _.neq( 4, 2, 1 );
  
console.log("Each arguments are not equal to previous one :", neq);

输出:

Each arguments are not equal to previous one : true

示例 4:

// Defining underscore contrib variable
var _ = require('underscore-contrib'); 
  
var neq  = _.neq( 2, 2, 2 );
  
console.log("Each arguments are not equal to previous one :", neq);

输出:

Each arguments are not equal to previous one : false