Lodash教程

Lodash negate method

语法

_.negate(predicate)
Creates a function that negates the result of the predicate func. The func predicate is invoked with the this binding and arguments of the created function.

参数

predicate (Function) − The predicate to negate.

输出

(Function) − Returns the new negated function.

实例

var _ = require('lodash');
function isEven(n) {
   return n % 2 == 0;
}
 
console.log(_.filter([1, 2, 3, 4, 5, 6], _.negate(isEven)));
Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

输出

[ 1, 3, 5 ]
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4