ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
## reject + [link](./reject "Link to this entry.") + [source](https://github.com/lodash/lodash/blob/4.5.0正式版/lodash.src.js#L8082 "View in source.") + [npm](https://www.npmjs.com/package/lodash.reject "See the npm package.") ``` _.reject(collection, [predicate=_.identity]) ``` 反向版 `_.filter`,这个方法返回 `predicate` 检查为非真值的元素。 ### 参数 1. collection (Array|Object) 需要遍历的集合 2. [predicate=_.identity] (Function|Object|string) 这个函数会处理每一个元素 ### 返回值 (Array) 返回过滤后的新数组 ### 示例 ``` var users = [ { 'user': 'barney', 'age': 36, 'active': false }, { 'user': 'fred', 'age': 40, 'active': true } ]; _.reject(users, function(o) { return !o.active; }); // => 结果: ['fred'] // 使用了 `_.matches` 的回调结果 _.reject(users, { 'age': 40, 'active': true }); // => 结果: ['barney'] // 使用了 `_.matchesProperty` 的回调结果 _.reject(users, ['active', false]); // => 结果: ['fred'] // 使用了 `_.property` 的回调结果 _.reject(users, 'active'); // => 结果: ['barney'] ```