Javascript Reference - How to some() function to check each value in a Javascript array








some() accepts two arguments.

  • a function to run on each item
  • an optional scope object.

some() runs the given function on every item and returns true if the function returns true for any one item.

The function passed in receives three arguments.

  • the array item value,
  • the position of the item in the array
  • the array object itself.




Example


var numbers = [1,2,3,4,5,4,3,2,1]; 
var someResult = numbers.some(function(item, index, array){ 
   return (item > 2); 
}); 
        
console.log(someResult); //true 

some() does not change the values contained in the array.

The code above generates the following result.