DEV Community

Discussion on: The moment I realized forEach() does not return anything.

Collapse
 
theosyslack_42 profile image
Theo Syslack

You might want to consider using Array.prototype.some. This will run a function against each element in an array, until something returns truthy. Then, it immediately stops and returns true. This will help a lot if you have a large number of items in the second array.
developer.mozilla.org/en-US/docs/W...

Collapse
 
kaynguyen profile image
Kay N.

Oh yeah totally forgot about that little guy. Thanks for mentioning! Will definitely use it next time similar needs come up!