In continuation of series of ECMAScript 5. This article describes some feature of Array in ECMAScript 5. some tests whether passed callbackfn in the array is true or false. It loops through each element of array in ascending order and triggers the callbackfn on each element. It returns true as soon as callbackfn returns true and it stops looping immediately. It returns false only if all callbackfn returns false. It also returns false if array is empty.
Array.some()
Signature
array.some(callbackfn [, thisArg])
callbackfn - It tests array elements. callbackfn should be defined as function (value[,index [,array]]).
thisArg- thisArg is optional. It is used to pass to callbackfn as this value.
Returns
It returns true as soon as callbackfn returns true and returns false if all the element in callbackfn returns false.
Example
var arr = [87, 22, 54, 9, 39, 30, 31, 76, 39, 2];
arr.every(function(x) { return x > 100; })
Output: false
arr.every(function(x) { return !(x % 2)})
Output: true
This ends the some feature of Array in ECMAScript 5.
|