Tip 5 Create Flexible Collections with Arrays

In this tip, you’ll learn how arrays maximize flexibility and give you a foundation for understanding all other collections.

In JavaScript, there used to be only two structures for collections of data: arrays and objects. That list is growing. Now there are maps, sets, weakmaps, weaksets, objects, and arrays.

When choosing a collection, you have to ask yourself what you need to do with the information. If you need to manipulate it in any way (add, remove, sort, filter, alter all members), then arrays are often the best collection. And even when you don’t use an array, you’ll almost certainly use ideas that you’d associate with arrays.

Arrays have a remarkable amount of flexibility. Because arrays ...

Get Simplifying JavaScript now with O’Reilly online learning.

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