The array of Javascript arrays, both an array and a dictionary (Dictionary).
Let's take a look at the use of arrays.
Copy Code code as follows:
var a = new Array ();
A[0] = "Acer";
A[1] = "Dell";
for (var i in a) {
alert (i);
}
The code above creates an array with each element being a string object.
The array is then traversed. Note that the result of I is 0 and 1,a[i] is a string.
This is much like the properties of the traversal object mentioned in the previous article.
Next look at the use of the dictionary.
Copy Code code as follows:
var computer_price = new Array ();
computer_price["Acer"] = 500;
computer_price["Dell" = 600;
Alert (computer_price["Acer"]);
We can even walk through the array like the above (the dictionary)
Copy Code code as follows:
for (var i in Computer_price) {
Alert (i + ":" + computer_price[i]);
}
Here I is the dictionary of each key value. The output results are:
Copy Code code as follows:
Next, take a look at the interesting things about JavaScript, or the example above.
We can think of Computer_price as a Dictionary object, and each of its key values is an attribute.
That is to say that Acer is a computer_price attribute. We can use it this way: Computer_price. Acer
Let's look at the simplified declarations of dictionaries and arrays.
Copy Code code as follows:
var array = [1, 2, 3]; Array
var array2 = {"Acer": $, "Dell": 600}; Dictionary
Alert (array2. Acer); 50
The statement to the dictionary is the same as the previous one. In our example, Acer is a key value, but also as a property of the Dictionary object.
The above is the entire content of this article, I hope you can enjoy, follow-up we will continue to update.