说我创建一个对象,如下所示:
let myObject = { "ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*" };
删除该属性regex以使其最终成为new 的最佳方法是什么myObject?
regex
myObject
let myObject = { "ircEvent": "PRIVMSG", "method": "newURI" };
像这样:
delete myObject.regex; // or, delete myObject['regex']; // or, var prop = "regex"; delete myObject[prop];
演示版
var myObject = { "ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*" }; delete myObject.regex; console.log(myObject);