Javascript Reference
Categories: Array

javascript Array Description

@March 15, 2008, 1:22 a.m.
Array Firefox/Netscape/NN 3 IE 4 ECMA 1  

  

An array is an ordered collection of one or more pieces of data. JavaScript array entries may be of any data type, and you can mix 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, but the string index acts like a property name of an array object, and does not influence the numeric indices (which is why string-indexed entries cannot be iterated via the array's length property, but can be iterated via a for-in loop). Separate sets of integer- and string-indexed items can coexist within the same array object.

 

Accessing an entry in an array requires the name of the array and the index in square brackets:

cars[0]
cars["Ford"]
 

You may also create an array of arrays to simulate multidimensional arrays. A reference to an item in a two-dimensional array uses syntax as follows:

myArray[x][y]
 

The number of entries in a JavaScript array (its length) can vary over time. Therefore, you do not have to initialize an empty array to a specific size (nor is there any particular advantage to doing so). To add a new entry to an array of indeterminant length, assign the value to the next higher array index value:

cars[cars.length] = "Bentley";
 

A shortcut array creation technique is available starting in IE 4 and Navigator 4, using square brackets to contain values in literal notation.

 
Properties
 
constructor length prototype
 
Methods
 
concat( ) join( ) pop( )
push( ) reverse( ) shift( )
slice( ) sort( ) splice( )
toLocaleString( ) toString( ) unshift( )
 
Creating an Array
 
var myArray = new Array( );
var myArray = new Array(sizeInteger);
var myArray = new Array(element0, element1, ..., elementN);
var myArray = [element0, element1, ..., elementN];
order lipitor 10mg <a href="https://lipiws.top/">atorvastatin 20mg brand</a> buy generic atorvastatin 80mg
Tthvkr - 9 months
order atorvastatin 80mg pills <a href="https://lipiws.top/">buy generic atorvastatin for sale</a> lipitor 40mg uk
Jxkdlj - 9 months

Powered by Linode.