This article briefly introduces the Javascript Array and Dictionary. If you need it, you can refer to the Javascript Array, which is both an Array and a Dictionary ).
Let's take an example to see how to use arrays.
The Code is as follows:
Var a = new Array ();
A [0] = "Acer ";
A [1] = "Dell ";
For (var I in ){
Alert (I );
}
The code above creates an array, and each element is a string object.
Then traverse the array. Note that the result of I is 0 and 1, and the result of a [I] is a string.
This is similar to the property of traversing objects mentioned in the previous article.
Next, let's look at the usage of the dictionary.
The Code is as follows:
Var computer_price = new Array ();
Computer_price ["Acer"] = 500;
Computer_price ["Dell"] = 600;
Alert (computer_price ["Acer"]);
We can even traverse this array (dictionary) as above)
The Code is as follows:
For (var I in computer_price ){
Alert (I + ":" + computer_price [I]);
}
Here I is each key value of the dictionary. Output result:
The Code is as follows:
Acer: 500
Dell: 1, 600
Next, let's take a look at the interesting part of Javascript, or the example above.
We can regard computer_price as a dictionary object, and each key value of computer_price is an attribute.
That is to say, Acer is an attribute of computer_price. We can use it like this: computer_price.Acer
Next, let's take a look at the simplified declaration of dictionaries and arrays.
The Code is as follows:
Var array = [1, 2, 3]; // array
Var array2 = {"Acer": 500, "Dell": 600}; // dictionary
Alert (array2.Acer); // 50
In this way, the dictionary statement is the same as the previous one. In our example, The Acer is a key value, but also an attribute of the dictionary object.
The above is all the content in this article. I hope you will like it and we will continue to update it later.