JavaScript every() and some()
finding if all or at least one element of an array would meet a condition
Motivation
Suppose we have an array and we wish to go through its elements, then find out if all elements meet a condition, or at least one does so...
We could use the built-in every()
and some()
functions to iterate and test for existence:
Summary
So, both every()
and some()
return a simple boolean indicating
a uniformity (in the case of
every()
) oran existence (in the case of
some()
) of a condition
the condition in question appears in the body of the callback function
that callback function gets passed into the parameter of the higher-order function,
every()
orsome()
Last updated