Tip 6 | Check Existence in an Array with Includes() |
In this tip, youâll learn how to find out if a value exists in an array without checking position.
Itâs easy to get so caught up in the big exciting changes in a language (such as the spread operator, which youâll see in a moment) that you miss the small changes that simplify common tasks.
Arrays now have an easy improvement to handle a common problem: testing existence. Testing existence is an important action, and itâs crucial in everything from ternaries (Tip 18, â Check Data Quickly with the Ternary Operator â), to short circuiting (Tip 19, â Maximize Efficiency with Short Circuiting â), to most conditionals in general.
Testing existence with JavaScript arrays has always ...
Get Simplifying JavaScript now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.