For JSON objects, you can refer to Wikipedia (Http://zh.wikipedia.org/zh-cn/JSON) and the official website (http://www.json.org/json-zh.html).
We often say that JavaScript native supports JSON, because we can think of JSON as a flexible application of JavaScript object objects.
Typically, we use JSON in the form of data interchange in the front and back table:
In code logic, however, more is the way of associative arrays. But even then, we rarely use object types as key-value pairs.
var a= {}, b= [];
A[B] = new Date (); The time value can be obtained by a[b].
The type of the key name can be an object , what a beautiful thing ah!
But there is one problem. If you want to use this, you need to have a condition: the data must be dynamically added. (currently in classmate this, there is no condition to test other browsers, currently tested IE8 and Sogou browser's IE kernel and weikit kernel)
The test code is as follows:
Copy Code code as follows:
var d = document.getElementById ("Hello"), obj = [1,2,3], a = {obj: "Test"};
A[d] = "DomElement";
Alert (A[obj]); Undefined
Alert (A[d]); DomElement
A[obj] = "Array Object";
Alert (A[obj]); Array Object