Copy codeThe Code is as follows: var Person = new Array ();
Person [0] = 120; // defines a Person's weight of 120
Person [1] = 21; // defines the Person's age, 21 years old
Document. write ("Weight =" + Person [0] + "age =" + Person [1]); // output the weight and age of the Person
Another interesting way to define arrays:Copy codeThe Code is as follows: var Person = new Array ();
Person ["weight"] = 50;
Person ["age"] = 40;
Document. write ("weight =" + Person ["weight"] + "age =" + Person ["age"]);
The above method is called "Join array" and indexes the array by a specific value. In fact, a numeric array can be treated as a special case of an associated array.
Using an associated array instead of a numeric array means that we can reference each element by its name rather than a subscript number, which greatly improves the readability of the script.