From the course: JavaScript: Arrays

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Do elements pass a test?

Do elements pass a test? - JavaScript Tutorial

From the course: JavaScript: Arrays

Do elements pass a test?

- [Instructor] Sometimes we need to determine whether or not an array passes a test, sometimes, or every time. Thankfully two array methods exist to help us some and every. These array methods function identically, both return booleans based on whether or not the functions criteria match some or every element in the array. With Some, as the name implies, if at least one element matches the criteria, it will return true. With every, every single element in the array must match the criteria for it to return a true value. The syntax for some and every should look very familiar as we've used this previously with, for each, find and find index,. Both array methods take a callback function that has three parameters. Element which is required, index which references the index of the current element and array, which is the array you're iterating over. This also has a parameter, this Arg, but we're going to keep things simple…

Contents