Chapter 7

Working with Arrays

IN THIS CHAPTER

Bullet Declaring an array variable

Bullet Populating an array with data

Bullet Iterating an array

Bullet Working with JavaScript’s Array object

In this chapter, you take your coding efficiency to an even higher level by exploring one of JavaScript’s most important concepts: the array. Arrays are important not only because they’re extremely efficient and very powerful but also because after you know how to use them, you’ll think of a thousand and one uses for them. To make sure you’re ready for your new array-filled life, this chapter explains what they are and why they’re so darn useful, and then explores all the fantastic ways that arrays can make your coding life easier.

What Is an Array?

In JavaScript, whenever you have a collection of variables with related data, you can group them together into a single variable called an array. You can enter as many values as you want into the array, and JavaScript tracks each value using an index number. For example, the first value you add is given the index 0. The second value you put into the array is given the index ...

Get JavaScript Essentials For Dummies 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.