JS thinking traverse the object

 

1  var json = {
 2  "name": "Hsiao Ming",
 3 "age": "10 ",
 4  "sex": "Man"
 5 }

 

 

 

for (var key in json); // key is just a variable name

Name // json object attributes; console.log (key)

console.log (json.key); // error, property values ​​json traversal if this is the case is not found, but because the key is the variable name, json object no key attribute, built a key attribute.

Console.log (json [key]); key is a variable, which is stored in the object attribute name json similar json [ "key"] == json [ "name"] == json [ "age"], so you can find the content stored in the property

}

              Object does have the properties of an object, the object attribute name or attribute name

Guess you like

Origin www.cnblogs.com/qisexin/p/11256567.html