Related array _ JavaScript skills for javascript Object-based indexing

Source: Internet
Author: User
We often say that JavaScript supports json native, because json is a flexible application of JavaScript Object. For more information about JSON objects, see wikipedia (http://zh.wikipedia.org/zh-cn/JSON) and the official website (http://www.json.org/json-zh.html ).

We often say that JavaScript supports json native, because json is a flexible application of JavaScript Object.

Generally, we use json as the format for data exchange between the front and back ends:

In the Code logic, more is the method of associating arrays. Even so, we seldom use the object type as the key name of the key-value pair.
Var a = {}, B = [];
A [B] = new Date (); // the time value can be obtained through a [B.

Key nameCan be an object.What a wonderful thing!

But there is a problem. If you want to use this method, you need to have a condition that the data must be dynamically added. (Currently, students have no conditions to test other browsers. Currently, IE8, sogou browser's IE kernel and weikit kernel are tested)

The test code is as follows:

The Code is as follows:


Var d = document. getElementById ("hello"), obj = [1, 2], a = {obj: "test "};
A [d] = "DOMElement ";
Alert (a [obj]); // undefined
Alert (a [d]); // DOMElement
A [obj] = "Array Object ";
Alert (a [obj]); // Array Object

Related Article

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.