Name

Array — NN 3 IE J2 ECMA 1

Synopsis

An array is an ordered collection of one or more pieces of data. JavaScript array entries may be of any data type, including different data types in the same array. Each entry in an array has an index assigned to it. The default behavior is for the index to be a zero-based integer (the first entry has an index of zero). An index value may also be a string. Accessing an entry in an array requires the name of the array and the index in square brackets:

cars[0]
cars["Ford"]

The number of entries in a JavaScript array (its length) can vary over time. To add a new entry to an array, assign the value to the next higher array index value:

cars[cars.length] = "Bentley"

Internet Explorer first recognized the Array object in Version 2 of the Jscript.dll for Internet Explorer 3.

Creating an Array

var myArray = new Array()
var myArray = new Array(sizeInteger)
var myArray = new Array(element0, element1, ..., elementN)

Properties

length
prototype

Methods

concat()
push()
slice()
join()
reverse()
sort()
pop()
shift()
unshift()

Get Dynamic HTML: The Definitive 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.