From the course: Learning Functional Programming with JavaScript ES6+

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Every/some

Every/some - JavaScript Tutorial

From the course: Learning Functional Programming with JavaScript ES6+

Start my 1-month free trial

Every/some

- [Instructor] Next, we're going to look at two built-in array functions that are pretty similar. These functions are called every and some. We saw in a previous video how to use JavaScript's filter function to find the elements in an array for which a given condition is true. Finding all the even numbers in an array of numbers, for example. JavaScript's built-in every and some functions are similar to this in that we pass them a function that returns either true or false for each element. But the difference is that instead of returning an array, every and some return a single Boolean, true or false. Every returns true if and only if a given condition is true for every single element in our array. Otherwise, it returns false. So, for example, if we have an array of all odd numbers and we call every with a function that checks if a number is odd, it will return true. But if there's a single even number in our array, it will return false. And, of course, if the array contains all even…

Contents