Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

TypeScript | Array every() Method

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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

array.every(callback[, thisObject])

Parameter: This method accepts 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 every element in this array satisfies the provided testing function. 
Below examples illustrate Array every() method in TypeScript

Example 1: 

JavaScript




<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.every(ispositive); 
    console.log( value );
</script>

Output: 

true

Example 2: 

JavaScript




<script>
    // Check for odd number 
    function isodd(element, index, array) 
    {  
       return (element % 2 == 1);  
    }   
    // Driver code
    var arr = [ 11, 89, 23, 7, 98 ]; 
      
    // Check for positive number 
    var value = arr.every(isodd); 
    console.log( value );
</script>

Output: 

false

My Personal Notes arrow_drop_up
Last Updated : 18 Jun, 2020
Like Article
Save Article
Similar Reads
Related Tutorials