JS some


JS Array.some() method checks whether at least one element satisfies a specific function. It returns true or false.

var arr = new Array(1,2,3,4,5);
var ret = arr.some(function(x) {return x < 6;})
alert(ret); //true
ret = arr.some(function(x) {return x == 3;})
alert(ret); //true
ret = arr.some(function(x) {return x > 30;})
alert(ret); //false

Combine with other array methods:

var arr = new Array(1,2,3,4,5);
var ret = arr.slice(2,4).some(function(x) {return x == 3;})
alert(ret);  //true


endmemo.com © 2024  | Terms of Use | Privacy | Home