1. braces {} indicate defining an object. In most cases, there must be a pair of attributes and values or functions.
For example, var LangShen = {"Name": "Langshen", "AGE": "28 "};
The above declares an object named "LangShen". multiple attributes or functions are separated by commas (,) because they are attributes of objects,
Therefore, you should use. (point) layer-by-layer access: LangShen. name, LangShen. AGE, of course, we can also use Arrays for access, such as LangShen ["Name"] And LangShen ["AGE"]. The results are the same.
This method is often used in JSON data structures. In addition, we often use it when writing function groups, such:
Copy codeThe Code is as follows:
Var LangShen = {
Name = function (){
Return "LangShen ";
},
Age = function (){
Return "28 ";
}
}
The call method is similar. Because it is a function group, add (), for example, alert (LangShen. Name ());
2. [] brackets indicate an array, which can also be understood as an array object.
For example, var LangShen = ["Name", "LangShen", "AGE", "28"];
Obviously, each value or function is independent. Multiple values are separated by commas (,). Because they are array objects, they are equal:
Var LangShen = Array ("Name", "LangShen", "AGE", "28 ");
Alert (LangShen [0]);
3. {} and [] are used together. As mentioned above, {} is an object and [] is an array. We can form an array of objects, for example:
Copy codeThe Code is as follows:
Var LangShen = {"Name": "Langshen ",
"MyWife": ["LuLu", "26"],
"MySon": [{"Name": "Son1" },{ "Name": "Son2" },{ "Name": "Son3"}]
}
From the above structure, the first attribute in an object is an attribute, the second is an array, and the third is an array containing multiple objects. Calling is also a layer-by-layer access. Object Attributes are superimposed with. (points), and arrays are accessed with [subscript.
For example, alert (LangShen. MySon [1]. Name );