主题
some
js
_.some(collection, [predicate=_.identity])
检查 predicate
是否对 collection
的任何元素返回真值。一旦 predicate
返回真值,迭代就会停止。使用三个参数调用谓词:(value, index|key, collection)。
¥Checks if predicate
returns truthy for any element of collection
. Iteration is stopped once predicate
returns truthy. The predicate is invoked with three arguments: (value, index|key, collection).
新增于
¥Since
0.1.0
参数
¥Arguments
collection
(数组|对象):要迭代的集合。¥
collection
(Array|Object): The collection to iterate over.[predicate=_.identity]
(函数):每次迭代调用的函数。¥
[predicate=_.identity]
(Function): The function invoked per iteration.
返回
¥Returns
(布尔):如果任何元素都通过谓词检查,则返回 true
,否则返回 false
。
¥(boolean): Returns true
if any element passes the predicate check, else false
.
示例
¥Example
js
_.some([null, 0, 'yes', false], Boolean);
// => true
var users = [
{ 'user': 'barney', 'active': true },
{ 'user': 'fred', 'active': false }
];
// The `_.matches` iteratee shorthand.
_.some(users, { 'user': 'barney', 'active': false });
// => false
// The `_.matchesProperty` iteratee shorthand.
_.some(users, ['active', false]);
// => true
// The `_.property` iteratee shorthand.
_.some(users, 'active');
// => true