Lodash教程

Lodash reject method

语法:

_.reject(collection, [predicate=_.identity])
The opposite of _.filter; this method returns the elements of collection that predicate does not return truthy for.

参数:

collection (Array|Object) − The collection to iterate over. [predicate=_.identity] (Function) − The function invoked per iteration.

输出:

(Array) − Returns the new filtered array.

例子:

var _ = require('lodash');
var users = [
   { user: 'Joe', age: 48, active: false },
   { user: 'Robert', age: 34, active: true },
   { user: 'Julie', age: 40, active: false },
   { user: 'Stafey', age: 36, active: true }
];
var result = _.reject(users, ['active', false]);
console.log(result);
Save the above program in tester.js. Run the following command to execute this program.

命令:

\>node tester.js

输出:

[
   { user: 'Robert', age: 34, active: true },
   { user: 'Stafey', age: 36, active: true }
]
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4