JavaScript: The Definitive Guide, Sixth Editio javaScript权威指南(第6版) pdf 文字版-文字版, javascript电子书, 和javascript 有关的电子书:

Array.some()

Array.some() ECMAScript 5


test whether a predicate is true for any element

Synopsis

array.some(predicate) array.some(predicate, o)

Arguments

predicate

A predicate function to test array elements

o The optional this value for invocations of predicate.

Returns

true if predicate returns true (or a truthy value) for at least one element of array or false if the predicate returns false (or a falsy value) for all elements.

Description

The some() method tests whether a condition holds for at least one element of an array. It loops through the elements of array, in ascending order, and invokes the specified predi cate function on each element in turn. If predicate returns true (or a value that converts to true), then some() stops looping and returns true immediately. If every invocation of predi catereturns false(or a value that converts to false), then some()returns false. When invoked on an empty array, some() returns false.

This method is very much like every(). See Array.every() and Array.forEach() for further details.

Example

[1,2,3].some(function(x) { return x > 5; }) // => false: no elts are > 5 [1,2,3].some(function(x) { return x > 2; }) // => true: some elts are > 3 [].some(function(x) { return true; }); // => false: always false for []

See Also

Array.every() , Array.filter() , Array.forEach()

欢迎转载,转载请注明来自一手册:http://yishouce.com/book/1/28132.html
友情链接It题库(ittiku.com)| 版权归yishouce.com所有| 友链等可联系 admin#yishouce.com|粤ICP备16001685号-1