js object

Object An
object is a compound value, in short, an object is a mapping of strings to values.

(1) The first is the establishment of the object.
There are 3 ways to create an object
var a = {};
var b = new Object();
var c = Object.create({x:1,y:2});
Note that Object.create() is a static function, Instead of supplying the call method of an object.

(2) Querying and setting of
objects Objects can use (.) or ([]) operators to obtain property values.
What is the difference between the two of them?
The right side of the (.) must be a simple identifier named after the property name.
([]) must be an expression that evaluates to a string, which is the name of the property.
var a ={i:1,j:'y'};
console.log(ai); //The result is 1
console.log(a['j']);//The result is j

(3) Traverse query
possible When querying an object, the queryer does not know the key value.
At this time, we need to traverse for/in
var aa ={a:1,b:2,c:3};
for(var i in aa){
   console.log(i);//result abc
   console.log(aa [i]);//result 1 2 3
}

(4) delete attribute
The delete operator deletes object properties. But delete just disconnects the property from the host object,
and does not operate the properties in the property.
Example var aa ={a:1,b:2,c:3};
     delete aa.a;
     console.log(JSON. stringify(aa)); //result {'b':2,'c':3}
     console.log(delete aa.a);//result true
note
     delete 1;
     console.log(delete 1); although no actual meaning, but he outputs true

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326786165&siteId=291194637