Home >>JavaScript Array Reference >JavaScript Array every() Method

JavaScript Array every() Method

JavaScript Array every() Method

The JavaScript Array.every() method checks whether all the given elements in an array pass a test by the provided condition and returns a Boolean value. When each given array element satisfying the condition then it returns true otherwise false.

Syntax:
array.every(function(currentValue, index, arr), thisValue)

Parameter Values

Parameter Description
function(currentValue, index, arr) It required index position to copy the elements to
currentValue The value of the current element Required
index It is optional and is used for the array index of the current element
thisValue It is optional and the value to be passed to the function to be used as its "this" value.

Browser Support

Method Chrome Edge Firefox Safari Opera
array.entries(); Yes 9.0 1.5 Yes Yes
Here is an example of JavaScript array every() Method:
<!DOCTYPE html>
<html>
<body>
<button onclick="myEvery()">click me</button>
<p id="every"></p>
<script>
var ages = [56, 45, 18, 65];
function checkAdult(age) {
  return age >= 18;
}
function myEvery() {
  document.getElementById("every").innerHTML = ages.every(checkAdult);
}
</script>
</body>
</html>
Output:

Example 2:
<!DOCTYPE html>
<html>
<body>
<script>
var num=[50,30,45,35,20];
function check(value)
{
  return value>30;
}
document.writeln(num.every(check));
</script>
</body>
</html>
Output:

No Sidebar ads