JavaScript Array Object JavaScript Array Object

These tutorials introduce the Array object, one of the most flexible data types JavaScript offers. Arrays have a dynamic size, can contain elements of different types, and support a number of useful methods (like on-the-fly sorting). A JavaScript array (of strings) vs. a JavaScript string, and a mixed data type array

What is an Array?

A JavaScript array is a collection of variables ("elements") referenced by the array name and the zero-based index of their position: "MyArray[0]" points to the first array element of MyArray.

Each array element is an independent variable, which can be of a different data type than other elements in the same array. Below, we declare a JavaScript array containing four elements: each is of a different data type.

var arlene = new Array("a string", 12, 47.845, true);

This perfectly valid JavaScript array contains as elements a string, an integer, a floating point number, and a boolean (a special JavaScript object).

Types of Arrays in JavaScript

Arrays are one-dimensional by default, but JavaScript also supports multi-dimensional arrays. A multidimensional array is an array of arrays: each element is itself an array. In later tutorials, you will learn how to create and use both one-dimensional and multidimensional arrays.

JavaScript also supports "associative arrays": by default, array elements are referenced through an auto-incremented index handled by the JavaScript interpreter. But you can create custom array referencing systems.

JavaScript Array Properties

Our tutorial will cover the three properties available to JavaScript arrays: length, constructor, and prototype. Length is the property that allows you at any time in your scripts to determine the number of available spots in an array - whether the spots have been initialized or not with an element.

JavaScript Array Methods

Our tutorials will cover the most common JavaScript array methods. Methods are special functions available to different types of objects; like other objects, JavaScript arrays have numerous manipulation and conversion methods.