Check Properties
var mouse = {
"name": "Betta",
"age": 3,
"varieties": "Milaoshu"
}
Mouse.hasownproperty ("name"); True
mouse.hasownproperty ("sex");//false
Add properties
Defines an object dog, then assigns a variety of attributes, then gives the color attribute, and finally traverses all attributes and values
var dog={
name: "Mango",
type: "King of the Will",
eat:function () {
alert ("Eat");
}
object.prototype.color= "White";
var name;
for (name in dog) {
document.write (name+ "" +dog[name]+ "<br>")
}
The effect is as follows
Name Mango
type will King
eat function () {alert ("Eat");}
Color White
Delete attribute
var cat = {
"name": "Tom",
"sex": "Man",
"color": "Yellow"
}
delete cat.name;
Cat.sex = undefined;
Cat.color = null;
Alert ("Name property exists:" + cat.hasownproperty ("name")); False
alert ("Sex property exists:" + cat.hasownproperty ("sex"));//true
alert ("Color property exists:" + cat.hasownproperty ( "Color")); True
Access Properties
var cat = {
"name": "Tom",
"sex": "Man",
"color": "Yellow"
}
var name1 = cat.name;// Accessing object Properties
var name2 = cat["name" via the dot operator;//access to object properties through bracket operators
There are two ways to create objects
var obj = new Object ();
Obj.name = "Mangguo";
Obj.age =;
var obj = {
name: "Mangguo",//name is the property name, "Mangguo" is the value
age:25
}