Chapter 18. The Array Object

IN THIS CHAPTER

  • Working with ordered collections of data

  • Simulating multidimensional arrays

  • Manipulating information stored in an array

  • New additions to JavaScript array handling

An array is one of the major JavaScript structures provided for storing and manipulating ordered collections of data. But unlike some other programming languages, JavaScript's arrays are very forgiving as to the kind of data you store in each cell or entry of the array. This allows, for example, an array of arrays, providing the equivalent of multidimensional arrays customized to the kind of data your application needs.

If you have not done a lot of programming in the past, the notion of arrays may seem like an advanced topic. But if you ignore their capabilities, you set yourself up for a harder job when implementing many kinds of tasks. Whenever we approach a script, one of our first thoughts is about the data being controlled by the application and whether handling it as an array will offer some shortcuts for creating the document and handling interactivity with the user.

We hope that by the end of this chapter you will not only be familiar with the properties and methods of JavaScript arrays but you will also begin to look for ways to make arrays work for you.

Structured Data

In programming, an array is defined as an ordered collection of data. You can best visualize an array as a table, not much different from a spreadsheet. In JavaScript, arrays are limited to a table holding one ...

Get JavaScript® Bible, Seventh Edition 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.