English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JavaScript Array every() Method

 JavaScript Array Object

The every() method tests whether all elements in the array pass the test implemented by the provided function.

Note:This method returns true for any condition placed on an empty array.

Syntax:

array.every(callback, thisArg)
var nums = [1, 30, 39, 29, 10, 13];
var bool = nums.every(function(element) {
return element >= 18;
});
document.getElementById("result").innerHTML = bool;
Test and See‹/›

Browser Compatibility

The numbers in the table specify the first browser version that fully supports the every() method:

Method
every()Is1.5IsIs9

Parameter Value

ParameterDescription
callback
The function to be executed for each element in the array.
Function Parameters:
  • currentValue(Required)-The index of the current element being processed in the array

  • index(Optional)-The index of the current element being processed in the array

  • array(Optional)- EachThe array being called

thisArgOptional. An object to be used as the value of "this" when the callback is executed, passed to the function.
If thisValue is omitted, the value of "this" is "undefined"

Technical Details

Return Value:If the callback function returns a true value for each array element, it is true; otherwise, it istrueOtherwise, it isfalse
JavaScript Version:ECMAScript 5

 JavaScript Array Object