object对象的增删改查

var obj = {
                    name : "XiaoQi",
                    sex : 'female',
                    age : 18,
                    stature : 160,
                    weight : 90,
                    apple : function () {
                        console.log('I am eating apple!!!');
                        this.weight -- ;
                    },
                    hamburger : function () {
                        console.log('I am eating hamburger!!It is delicious!!!');
                        this.weight ++ ;
                    }
                }

增:

 

obj.site = "ZheJiang";

删:

delete this.weight;

改:

obj.name = “QiQi";

查:

1.在控制台中:

obj.sex;

2.在javascript标签中:

console.log(obj.sex);

猜你喜欢

转载自www.cnblogs.com/oo5lll/p/12006834.html