Copy codeThe Code is as follows:
Var a = ["apple", "peach", "banala"];
The above is another definition of an array, which is equivalent
Copy codeThe Code is as follows:
Var a = new Array ();
A. push ("apple ");
A. push ("peach ");
A. push ("banala ");
Copy codeThe Code is as follows:
Var B = {a: "apple", p: "peach", B: "banala "};
The preceding is a json object.
There are two concise special symbols [] and {}. they are in the form of objects. [] can not only represent arrays, but can directly set values and access values through object attributes. For example:
Copy codeThe Code is as follows:
Var c = [];
C ["a"] = "apple ";
C ["B"] = "banala ";
Or
Copy codeThe Code is as follows:
Var c = {};
C ["a"] = "apple ";
C ["B"] = "banala ";
Their functions and functions are the same, with only minor differences.
During access, you can directly use the following attributes:
Copy codeThe Code is as follows:
Alert (c ["a"]);
"Apple" is displayed ".
To traverse, you can use:
Copy codeThe Code is as follows:
<PRE class = html name = "code"> for (var key in c)
Alert (c [key]); </PRE>
<PRE> </PRE>
In this way, all attribute values are displayed.
<P> </P>
<P> of course, jquery has an each traversal function. You can also access each attribute and value. But this is only </P>
<PRE class = javascript name = "code"> var c ={}; </PRE>.
<PRE> </PRE>
<PRE class = html name = "code"> <PRE class = html name = "code"> var c = []; </PRE> <BR>
No. <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> it is convenient to use an object. It is much faster than to use an array. the time complexity of searching for a value in an array is O (n ), the time complexity of using objects is only O (1), so objects are used to store values in most cases. </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>