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


Array.some() ECMAScript 5

test whether a predicate is true for any element


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



A predicate function to test array elements

o The optional this value for invocations of predicate.


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.


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.


[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()

友情链接It题库(| 版权归yishouce.com所有| 友链等可联系|粤ICP备16001685号-1