💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
## every + [link](./every "Link to this entry.") + [source](https://github.com/lodash/lodash/blob/4.5.0正式版/lodash.src.js#L7541 "View in source.") + [npm](https://www.npmjs.com/package/lodash.every "See the npm package.") ``` _.every(collection, [predicate=_.identity]) ``` 通过 `predicate` 检查集合中的元素是否都返回 真值,只要 `predicate` 返回一次假值,遍历就停止,并返回 false。 `predicate` 会传入3个参数:(value, index|key, collection) ### 参数 1. collection (Array|Object) 需要遍历的集合 2. [predicate=_.identity] (Function|Object|string) 这个函数会处理每一个元素 ### 返回值 (boolean) 返回 true,如果所有元素经 predicate 检查都为真值,否则返回 false。 ### 示例 ``` _.every([true, 1, null, 'yes'], Boolean); // => false var users = [ { 'user': 'barney', 'active': false }, { 'user': 'fred', 'active': false } ]; // 使用了 `_.matches` 的回调结果 _.every(users, { 'user': 'barney', 'active': false }); // => false // 使用了 `_.matchesProperty` 的回调结果 _.every(users, ['active', false]); // => true // 使用了 `_.property` 的回调结果 _.every(users, 'active'); // => false ```