Skip to content

reject

js
_.reject(collection, [predicate=_.identity])

选项对象。此方法返回 predicate 未返回真值的 collection 元素。

¥The opposite of _.filter; this method returns the elements of collection that predicate does not return truthy for.

新增于

¥Since

0.1.0

参数

¥Arguments

  1. collection (数组|对象):要迭代的集合。

    ¥collection (Array|Object): The collection to iterate over.

  2. [predicate=_.identity] (函数):每次迭代调用的函数。

    ¥[predicate=_.identity] (Function): The function invoked per iteration.

返回

¥Returns

(数组):返回新的过滤数组。

¥(Array): Returns the new filtered array.

示例

¥Example

js
var users = [
  { 'user': 'barney', 'age': 36, 'active': false },
  { 'user': 'fred',   'age': 40, 'active': true }
];

_.reject(users, function(o) { return !o.active; });
// => objects for ['fred']

// The `_.matches` iteratee shorthand.
_.reject(users, { 'age': 40, 'active': true });
// => objects for ['barney']

// The `_.matchesProperty` iteratee shorthand.
_.reject(users, ['active', false]);
// => objects for ['fred']

// The `_.property` iteratee shorthand.
_.reject(users, 'active');
// => objects for ['barney']

Lodash v4.17 中文网 - 粤ICP备13048890号