ES6 - Array Method some()



some() method tests whether some element in the array passes the test implemented by the provided function.

Syntax

array.some(callback[, thisObject]);    

Parameter Details

  • callback − Function to test for each element.

  • thisObject − Object to use as this when executing callback.

Return Value

If some element passes the test, then it returns true, otherwise false.

Example

function isBigEnough(element, index, array) { 
   return (element >= 10); 
} 
var retval = [2, 5, 8, 1, 4].some(isBigEnough); 
console.log("Returned value is : " + retval ); 

var retval = [12, 5, 8, 1, 4].some(isBigEnough); 
console.log("Returned value is : " + retval );   

Output

Returned value is : false 
Returned value is : true
Advertisements