Lodash _.neq() 方法
Lodash是一个基于 underscore.js 的 JavaScript 库。 Lodash 有助于处理数组、字符串、对象、数字等。
_.neq() 方法检查每个参数是否不等于前一个参数,使用松散不等式 (!=) 并相应地返回一个布尔值。
句法:
_.neq( val1, val2, ..., valn )
参数:此方法采用可变数量的值对它们进行操作。
返回值:此方法返回一个布尔值。
注意:这在普通 JavaScript 中不起作用,因为它需要安装 lodash contrib 库。 Lodash contrib 库可以使用npm install lodash-contrib –save 安装。
示例 1:
Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib');
// Using the _.neq() method
var neq = _.neq( 3, 1 );
console.log(
"Each arguments are not equal " +
"to previous one :", neq
);
Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib');
// Using the _.neq() method
var neq = _.neq( 8, 8 );
console.log(
"Each arguments are not equal " +
"to previous one :", neq
);
Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib');
// Using the _.neq() method
var neq = _.neq( 8, 6, 4, 12 );
console.log(
"Each arguments are not equal " +
"to previous one :", neq
);
Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib');
// Using the _.neq() method
var neq = _.neq( 8, 8, 8, 8 );
console.log(
"Each arguments are not equal " +
"to previous one :", neq
);
输出:
Each arguments are not equal to previous one : true
示例 2:
Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib');
// Using the _.neq() method
var neq = _.neq( 8, 8 );
console.log(
"Each arguments are not equal " +
"to previous one :", neq
);
输出:
Each arguments are not equal to previous one : false
示例 3:
Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib');
// Using the _.neq() method
var neq = _.neq( 8, 6, 4, 12 );
console.log(
"Each arguments are not equal " +
"to previous one :", neq
);
输出:
Each arguments are not equal to previous one : true
示例 4:
Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib');
// Using the _.neq() method
var neq = _.neq( 8, 8, 8, 8 );
console.log(
"Each arguments are not equal " +
"to previous one :", neq
);
输出:
Each arguments are not equal to previous one : false