O'Reilly logo

Object-Oriented JavaScript - Third Edition by Stoyan Stefanov, Ved Antani

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Collections

ES6 introduces four data structures-Map, WeakMap, Set, and WeakSet. JavaScript, when compared to other languages such as Python and Ruby, had a very weak standard library to support hash or Map data structures or dictionaries. Several hacks were invented to somehow achieve the behavior of a Map by mapping a string key with an object. There were side effects of such hacks. Language support for such data structures was sorely needed.

ES6 supports standard dictionary data structures; we will look at more details around these in the next section.

Map

Map allows arbitrary values as keys. The keys are mapped to values. Maps allow fast access to values. Let's look at some examples of maps:

 const m = new Map(); //Creates an empty Map m.set('first', ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required