5. Arrays and Dictionaries

Objects are JavaScript’s most versatile data structure. Depending on the situation, an object can represent a fixed record of name-value associations, an object-oriented data abstraction with inherited methods, a dense or sparse array, or a hash table. Naturally, mastering such a multipurpose tool demands different idioms for different needs. In the preceding chapter we studied the use of structured objects and inheritance. This chapter tackles the use of objects as collections: aggregate data structures with varying numbers of elements.

Item 43: Build Lightweight Dictionaries from Direct Instances of Object

At its heart, a JavaScript object is a table mapping string property names to values. This makes objects pleasantly ...

Get Effective JavaScript: 68 Specific Ways to Harness the Power of 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.