JS in {},[] brackets, curly braces use detailed

Source: Internet
Author: User

A, {} curly brace, which means defining an object, in most cases a pair of properties and values, or a function.

For example: var langshen = {"Name": "Langshen", "Age": "28"}; The above declares an object named "Langshen", where multiple properties or functions are separated by, (comma), because it is an object's property, so when accessed, it should be used. (dot) to layer access: Langshen.name, Langshen.age, of course, we can also use an array of ways to access, such as: langshen["Name"], langshen["age", the result is the same. This notation, often used in JSON data structures, is often used when we write function groups, such as:

var langshen = {
Name = function () {
return "Langshen";
},
Age = function () {
Return "28";
}
}

It is called the same way, because it is a function group, so add (), such as: Alert (Langshen.name ());

Two, [] brackets, which represent an array, can also be understood as an array object.

such as: var langshen = ["Name", "Langshen", "Age", "28"]; Obviously, each value or function is independent, with multiple values separated by only, (comma), because it is an array object, so it equals: var Langshen = Array ("Name", "Langshen", "Age", "28"); When accessed, it is also an array of alert (langshen[0]);

Three, {} and [] with, as we said before, {} is an object, [] is an array, we can make up an array of objects, such as:
var langshen = {"Name": "Langshen",
"MyWife": ["LuLu", "26"],
"Myson": [{"Name": "Son1"},{"name": "Son2"},{"name": "Son3"}]
}

From the structure above, the first item inside an object is a property, the second item is an array, and the third is an array containing multiple objects. Call up, is also a layer of access, the properties of the object with. (dot) overlay, array with [subscript] to access.

such as: Alert (langshen.myson[1). Name);

Reference: http://www.jb51.net/article/27119.htm

JS in {},[] brackets, curly braces use detailed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.