When the array is composed only of variables, is called a mono-dimensional array . Here's a way to represent it:
|Data||data 1||data 2||data 3||data 4|
- The first element in an array always has an index of 0.
- In an array of n elements, the nth element has the n-1 index.
When a array contains other arrays is referred to as a multidimensional arrays. Here is a representation of a multidimensional array:
|data 2 (array)
|data 4 (tableau)
Creating an array
var MyArray = ["data 1", "data 2", "data 3", "data 4"];
var MyArray = new Array("data 1", "data 2", "data 3", "data 4");
The array is initialized with the above value. It should be noted that n array must be declared before it is assigned values??.
The declaration of an array is as follows:
var MyArray = new Array();
How to access the data?
Access to the elements of an array is done by writing the name of the array followed by brackets containing the index of the element.
var MyArray = ["Teebo",
document.write("The 4th element of the array is "+MyArray);
// Display "The 4th element of the array is Kalamit"
To create an associative array, you have to declare an array variable, then write the name of the array, followed by a name (index) between brackets and assign the data usng assignment operator:
MyArray = "Bonjour";
MyArray["Pierre"] = 12;
MyArray["Jean-François"] = 25;
Working with tables
Original document published on CommentcaMarche.net
Published by jak58
Latest update on May 20, 2013 at 11:38 AM by jak58.