JavaScript Array every() Method

You are Here:

JavaScript Array every() Method

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

Note: This method does not alter the original array.

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <p>Is Smith passed all exams?</p> <script> var john = [55, 95, 33, 75]; var smith = [70, 80, 48, 95]; var passMark = 45; function checkPass(mark) { return mark >= passMark; } document.write(smith.every(checkPass)); </script> </body> </html>

Syntax

Array.every(function(value, index, arr), thisArg); //or Array.every(functionName);

Parameter Values

ValueTypeExplanation
function(value, index, arr)RequiredFunction to test for each element in an array.
Value - Specifies a value or element in an array.
index - Specifies the index of a value or element in an array.
arr - Specifies the whole array.
thisArgOptionalSpecifies a value against which each element in an array is tested.

Return Values

ValueExplanation
trueIf every element in an array passes the test.
If the given array is empty.
falseIf any of the elements in an array fails the test.

Example

HTML Online Editor
<!DOCTYPE html> <html> <body> <p>Is John passed all exams?<p> <script> var john = [55, 95, 33, 75]; var smith = [70, 80, 48, 95]; var passMark = 45; function checkPass(mark, index, arr) { return mark >= this; } document.write(john.every(checkPass, passMark)); </script> </body> </html>

Reminder

Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.

We are working to cover every Single Concept in JavaScript.

Please do google search for:

Join Our Channel

Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.

This channel is primarily useful for Full Stack Web Developer.

Share this Page

Meet the Author