Copy Code code as follows:
var a=["Apple", "Peach", "Banala"];
This is another way of defining an array, which is equivalent to
Copy Code code as follows:
var a=new Array ();
A.push ("Apple");
A.push ("Peach");
A.push ("Banala");
Copy Code code as follows:
var b={a: "Apple", p: "Peach", B: "Banala"};
This is a JSON object
There are two simple special symbols [] and {}. They are the form of an object where [] not only can you represent an array, you can set values and access values directly from the object's properties. For example:
Copy Code code as follows:
var c=[];
C["A"]= "Apple";
c["B"]= "Banala";
Or
Copy Code code as follows:
var c={};
C["A"]= "Apple";
c["B"]= "Banala";
Their function and function are the same, only a small difference, said later.
Access can be accessed directly by the attribute:
Copy Code code as follows:
Displays "Apple".
To traverse, you can pass:
Copy Code code as follows:
<pre class=html name= "code" >for (Var key in C)
Alert (C[key]);</pre>
<PRE></PRE>
This will show all the property values.
<P></P>
<P> of course, there is a each traversal in jquery, and you can access individual properties and values. But this is only when </P>
<pre class=javascript name= "code" >var c={};</pre> situation, if it is
<PRE></PRE>
<pre class=html name= "code" ><pre class=html name= "code" >var
You can't. <BR>
<P></P>
<P> then use </P>
<P></P>
<pre class=javascript name= "code" >$.each (c, Function (key, Val) {
Alert (key+ ":" +val);
});</pre><br>
<P></P>
<P> using objects is convenient, more efficient than using arrays, the time complexity of finding a value in an array is O (n), and the time complexity of using an object is only O (1), so in most cases the object is used to store the value. </P>
<P><BR>
</P>
<P><BR>
</P>
<PRE></PRE>
<PRE></PRE>
<PRE></PRE>
<PRE></PRE>
<PRE></PRE>
<PRE></PRE>
<PRE></PRE>
<PRE></PRE>
<PRE></PRE>
<PRE></PRE>
<PRE></PRE>
<PRE></PRE>
<PRE></PRE>
<PRE></PRE>
<PRE></PRE>
<PRE></PRE>
</PRE>