当前位置:网站首页>JS delete object attribute

JS delete object attribute

2022-06-23 20:43:00 It workers

Suppose you create an object using the following code :

let myObject = {
    "ircEvent": "PRIVMSG",
    "method": "newURI",
    "regex": "^http://.*"
};

If you want to delete regex attribute , Make the new object as follows :

let myObject = {
    "ircEvent": "PRIVMSG",
    "method": "newURI"
};

How do we delete objects regex Attribute? ?

Use JavaScript Of delete The operator , Can solve this problem .

for example , The above code can be changed to :

delete myObject.regex;
// or,
delete myObject['regex'];
// or,
var prop = "regex";
delete myObject[prop];

For you yes delete Operators are of great interest , You can see kangax Write an article about delete Statement , understand delete.

That's all js How to delete an operator .

原网站

版权声明
本文为[It workers]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/12/202112291651590972.html