TypeScript | Array some() Method

The Array.some() is an inbuilt TypeScript function which is used to check for some element in the array passes the test implemented by the provided function.
Syntax:

array.some(callback[, thisObject])

Parameter: This method accept two parameter as mentioned above and described below:

  • callback : This parameter is the Function to test for each element.
  • thisObject : This parameter is the Object to use as this when executing callback.

Return Value: This method returns true if some element in this array satisfies the provided testing function. 
Below example illustrate the  Array  some() method in TypeScriptJS:
Example 1: 

JavaScript

filter_none

edit
close

play_arrow

link
brightness_4
code

<script>
    // check for positive number 
    function ispositive(element, index, array)
    
       return element > 0;
    
    
    // Driver code
    var arr = [ 11, 89, 23, 7, 98 ]; 
      
    // check for positive number 
    var value = arr.some(ispositive); 
    console.log( value );
</script>

chevron_right


Output: 



true

Example 2: 

JavaScript

filter_none

edit
close

play_arrow

link
brightness_4
code

<script>
    // check for even number 
    function iseven(element, index, array) 
    {  
       return (element % 2 == 0);  
    }   
    // Driver code
    var arr = [ 11, 89, 23, 7, 91 ]; 
      
    // check for positive number 
    var value = arr.some(iseven); 
    console.log( value );
</script>

chevron_right


Output: 

false

full-stack-img




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.