Open In App

TypeScript | Array every() Method

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:



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: 






<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: 




<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

Article Tags :