JS-152-Objects-Arrays
  • Introduction
  • 04-Objects
    • OOP-Basics
      • Overview
      • Coding the Example
    • Prototypes
      • Object Prototypes
      • Prototypes Continued
    • Inheritance
      • Inheritance
    • Synopsis
      • Synopsis
    • Challenges
    • Solutions
      • Constructor Function
        • Person Constructor
        • Explanation
      • Inheritance Challenge
        • Code
        • Explanation
      • Family Challenge
        • Child
        • Pet
  • 05-Arrays
    • Array Basics
      • Array Overview
      • Creating an Array
      • Individual Elements and Length
      • Iterating Over Arrays
    • Array Methods
      • Methods Overview
      • .join() Method
      • .reverse() Method
      • .split() Method
      • .replace() Method
      • .splice() Method
      • .map() Method
      • .indexOf() Method
      • .filter() Method
      • .every() Method
    • Palindrome Algorithm
    • Array Challenges
    • Solutions
      • First and Last
        • First Element
        • Last Element
      • Most Frequent
      • Largest and Smallest
        • Single Array
        • Multiple Arrays
      • Missing Number
      • "Arrays" in the DOM
      • Sorting
        • Bubble Sort
        • Selection Sort
    • Resources
Powered by GitBook
On this page
  1. 05-Arrays
  2. Array Methods

.every() Method

Use the .every() method if you want to check if every element in the array passes a condition. In this example, we'll check to make sure that everyone that has registered is above the age of 18.

var ages = [ 34, 27, 43, 18, 59, 22, 40, 25 ]
var over18 = ages.every(function(element) {
  return element > 18;
});
console.log(over18);

Our output was false. The fourth element in our array is 16, which is obviously not greater than 18. As a result the entire array is false. If you got rid of 16, the array would return true. Because our function is element > 18 an element with a value of exactly 18 would not work either.

Previous.filter() MethodNextPalindrome Algorithm

Last updated 7 years ago