Tip 10 Use Objects for Static Key-Value Lookups

In this tip, you’ll learn why objects are the best collection for simple key-value lookups.

You probably noticed that I love arrays. But they are not appropriate in many situations. As you saw, it is always possible to store any type of information in arrays—they are really are that flexible—but it can make things more confusing than necessary. And you often end up obscuring information more than you communicate it.

What if you had some data and you wanted to conditionally apply some colors in the UI. You want the data to be red if data was below threshold, green if everything is within normal range, and blue if some data was above a threshold. As usual, some very smart designer with a ...

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.