CHAPTER 4

image

Arrays

An array is a data structure used for storing a collection of values. JavaScript arrays can be grouped into three kinds: numeric, associative, and multidimensional. The distinction between these arrays is only conceptual, as JavaScript considers them all to be array objects.

Numeric Arrays

Numeric arrays store each element in the array with a numeric index. An empty array can be created using the array constructor in the following way.

var a = new Array(); // empty array

To add elements to the array you can reference them one at a time by placing the element’s index inside square brackets. Assigning a value to an element automatically ...

Get JavaScript Quick Syntax Reference 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.