Open In App

TypeScript | Array every() Method

Last Updated : 18 Jun, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

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


Similar Reads

How does TypeScript support optional parameters in function as every parameter is optional for a function in JavaScript ?
Optional parameters are those parameters whose value may or may not be provided as an argument during the function call. Their value is set to undefined when they are not provided as an argument. It is different from a default parameter for which we need to provide a default value at the time of defining the function. This default value is used in
4 min read
TypeScript | Array unshift() Method
The Array.unshift() is an inbuilt TypeScript function that is used to add one or more elements to the beginning of an array and returns the new length of the array. Syntax: array.unshift( element1, ..., elementN ) Parameter: This method accepts n number of similar elements. element1, ..., elementN : This parameter is the elements to add to the fron
1 min read
TypeScript Array toString() Method
The Array.toString() is an inbuilt TypeScript function that is used to get a string representing the source code of the specified array and its elements. Syntax: array.toString() Parameter: This method does not accept any parameter. Return Value: This method returns the string representing the array. Below example illustrate the String toString() m
1 min read
TypeScript Array splice() Method
The Array.splice() is an inbuilt TypeScript function which is used to change the content of an array, adding new elements while removing old elements.Syntax: array.splice(index, howMany, [element1][, ..., elementN]); Parameter: This method accept three parameter as mentioned above and described below: index : This parameter is the index at which to
1 min read
TypeScript | Array sort() Method
The Array.sort() is an inbuilt TypeScript function which is used to sort the elements of an array. Syntax: array.sort( compareFunction ) Parameter: This method accept a single parameter as mentioned above and described below: compareFunction : This parameter is the function that defines the sort order Return Value: This method returns the sorted ar
1 min read
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
1 min read
TypeScript Array slice() Method
The Array.slice() is an inbuilt TypeScript function which is used to extract a section of an array and returns a new array.Syntax: array.slice( begin [,end] ); Parameter: This method accepts two parameter as mentioned above and described below: begin : This parameter is the Zero-based index at which to begin extraction.end : This parameter is the Z
1 min read
TypeScript | Array shift() Method
The Array.shift() is an inbuilt TypeScript function which is used to remove the first element from an array and returns that element. Syntax: array.shift(); Parameter: This methods does not accept any parameter. Return Value: This method returns the removed single value of the array. Below example illustrate the Array shift() method in TypeScriptJS
1 min read
TypeScript Array reverse() Method
The Array.reverse() is an inbuilt TypeScript function which is used to reverses the element of an array. Syntax: array.reverse(); Parameter: This methods does not accept any parameter. Return Value: This method returns the reversed single value of the array. Below examples illustrate the Array reverse() Method in TypeScript. Example 1: C/C++ Code /
1 min read
TypeScript | Array reduceRight() Method
The Array.reduceRight() is an inbuilt TypeScript function which is used to apply a function against two values of the array as to reduce it to a single value in a right to left manner. Syntax: array.reduceRight(callback[, initialValue]) Parameter: This method accept two parameter as mentioned above and described below: callback : This parameter is
1 min read