Home  >  Article  >  Web Front-end  >  Js method to dynamically add and delete object properties

Js method to dynamically add and delete object properties

一个新手
一个新手Original
2017-09-21 10:52:462232browse

var obj = {} 或  var obj = new Object()
//1.对象.属性 = 赋值
obj.aaa = 1
//2.对象[属性] = 赋值  
obj["aaa"] = 1;
方法2中的属性可以为变量,例如
var a = "aaa";
obj[a] = 1;
====================  删除
delete obj.aaa
delete obj["aaa"]

The above is the detailed content of Js method to dynamically add and delete object properties. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn