We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
some()
every()
These help you test if something is true for every element or some elements of an array.
We need some data to test, consider an array of numbers;
const nums = [34, 2, 48, 91, 12, 32];
Now let's say we want to test if every number in the array is less than 100.
100
nums.every(n => n < 100);
nums.every(n => n < 100)
// true => all numbers in the array are less than 100
every
false
true
some also works very similar to every
some
some loops over the array elements left to right.
For each iteration, it calls the given function with the current array element as its 1st argument.
The loop continues, until the function returns a truthy value and in that case some returns true - otherwise it returns false
Now let's use some to test if some number in the array is odd,
nums.some(n => n % 2 == 1);
// true => 91 is odd