TypeScript – Array some()

some() method

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 );

On compiling, it will generate the same code in JavaScript.

Its output is as follows โˆ’

Returned value is : false 
Returned value is : true

Previous Page:-Click Here

Leave a Reply