Testing truth conditions

Beyond simply filtering collections, you often need to test a condition of a collection. This could include filtering a collection, and then answering a simple yes/no about the results. In those cases where you need to check a truth condition of a collection, it's often easier to perform the test at the end of a chain. There's usually no need to write several statements and allocate several variables along the way.

Testing if a collection contains an item

Perhaps, the most straightforward test we can perform is whether or not a collection contains an item we're looking for. The contains() function is handy in cases like these because it is easy to attach to the end of a chain that's performing some other operations beforehand. ...

Get Lo-Dash Essentials 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.