One great thing about Array.prototype.some and Array.prototype.every is that they don't traverse the entire array if they found a true case for some, or a false case for every. So...
[false,false,true,false,false].some(Boolean);// stops in index 2[true,false,true,true,true].every(Boolean);// stops in index 1
Another good method of Array that is not used nearly enough is Array.prototype.includes, which can replace Array.prototype.indexOf in several scenarios:
One great thing about
Array.prototype.some
andArray.prototype.every
is that they don't traverse the entire array if they found atrue
case forsome
, or afalse
case forevery
. So...Another good method of
Array
that is not used nearly enough isArray.prototype.includes
, which can replaceArray.prototype.indexOf
in several scenarios:Thanks for sharing, Rakhi!
Definitely!!
For the
includes()
andindexOf()
, I agree! I have personally used both methods in my codebase, I might end up writing another post for them.Thanks for sharing Luke.