This object is not that object. Continuation of the second update. .
Yesterday we talked about the basic concepts and creation of objects. Today we will talk about its other methods:
1. Two ways to access properties: dot syntax and [] syntax
1 var dog =new Object(); 2 dog.name="阿黄"; 3 dog.age="2"; 4 5 //点语法用来访问对象的属性和方法 6 alert(dog.name); 7 8 //[]语法来访问对象属性 9 alert(dog["name"]);//var a="name";alert(dog[a]);10 11 //dog.name=dog["name"]; 他俩是等价的
Both dot syntax and [ ] syntax can access the properties of an object, but there are also differences:
1. Dot syntax mainly conforms to the variable naming rules;
2.[ ] syntax can use variables;
3.[ ] syntax can use invalid js characters; # 4. Dot syntax can be completely replaced with [ ] syntax, but not vice versa;
5. [ ] syntax can use numbers, keywords, and reserved words to access object properties, but dot syntax cannot.
2. Use
for into traverse the object
1 //对象属性的遍历,Key是属性名2 for(var Key in dog){3 console.log(dog[Key]);4 //dog[key]==dog[属性名]5 //console.log(Key);6 }
Delete attributes
## 4. hasOwnProperty()
5. instanceof
The above is the detailed content of Detailed explanation of some usages of javascript objects. For more information, please follow other related articles on the PHP Chinese website!