企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
## some + [link](./some "Link to this entry.") + [source](https://github.com/lodash/lodash/blob/4.5.0正式版/lodash.src.js#L8227 "View in source.") + [npm](https://www.npmjs.com/package/lodash.some "See the npm package.") ``` _.some(collection, [predicate=_.identity]) ``` 通过 predicate 检查集合中的元素是否存在任意真值的元素,只要 predicate 返回一次真值,遍历就停止,并返回 true。 predicate 会传入3个参数:(value, index|key, collection)。 ### 参数 1. collection (Array|Object) 需要遍历的集合 2. [predicate=_.identity] (Function|Object|string) 这个函数会处理每一个元素 ### 返回值 (boolean) 返回 true,如果任意元素经 predicate 检查都为真值,否则返回 false。 ### 示例 ``` _.some([null, 0, 'yes', false], Boolean); // => true var users = [ { 'user': 'barney', 'active': true }, { 'user': 'fred', 'active': false } ]; // 使用了 `_.matches` 的回调结果 _.some(users, { 'user': 'barney', 'active': false }); // => false // 使用了 `_.matchesProperty` 的回调结果 _.some(users, ['active', false]); // => true // 使用了 `_.property` 的回调结果 _.some(users, 'active'); // => true ```