O'Reilly logo

Jump Start JavaScript by Don Nguyen, Ara Pehlivanian

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

Chapter 3Arrays

We saw in Chapter 2 how variables store different types of data. But in the case of something like a to-do list, where you have more than one item to deal with, you're going to need a way to store a collection of data. This is where arrays come in.

Creating an Array

You can create an array in a couple of ways:

var myArray = new Array();

Or:

var myArray = [];

The [] notation is called an array literal, and it represents an empty array. It’s less verbose and safer to use than the new Array() syntax, because the Array constructor can be overwritten and potentially replaced with malicious code; for example, a function that masquerades as an array but sends any data you place in it to a third-party server on the Internet. Using the ...

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