7SETS AND MAPS

image

For most of its history, JavaScript had only one type of collection, which was represented by the Array type. (Although some developers may argue that all nonarray objects are just collections of key-value pairs, their intended use was originally quite different from arrays.) Arrays in JavaScript are used just like arrays in other languages, but before ECMAScript 6, the lack of other collection options meant arrays were often used as queues and stacks as well. Because arrays use only numeric indexes, developers used nonarray objects whenever a nonnumeric index was necessary. That technique led to custom implementations of sets and ...

Get Understanding ECMAScript 6 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.