Home > Article > Web Front-end > How to use every method
The every() method in How to use every method checks all elements in the array and executes the function. If the function returns false in any array loop and does not check the remaining elements, this loop exits. The array has no values and the every() method will not be executed. It also doesn't change the original array.
Let’s take a look at the specific usage of the every method
The basic syntax of the every method is as follows
array.every(function(currentValue, index, arr), thisValue)
Let’s look at an example
First we initialize an array named heights with some numeric elements. Then use the every() method to find if any array element is greater than 25
The code is as follows
<!DOCTYPE html> <html> <head> <title></title> <meta charset="utf-8"> </head> <body> <script type="text/javascript"> var heights = [15, 24, 33, 12]; function checkHeight(a) { return a >= 25; } var result = heights.every(checkHeight); console.log(result); </script> </body> </html>
The running result is displayed as: false
every() The method returns true or false based on whether each element in the array passes the condition given in the callback function.
This article ends here. For more exciting content, you can pay attention to the relevant column tutorials on the php Chinese website! ! !
The above is the detailed content of How to use every method. For more information, please follow other related articles on the PHP Chinese website!