Say I create an object thus:
var myJSONObject =
{"ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*"};
What is the best way to remove the property 'regex'? i.e. I would like to end up with myJSONObject such that:
myJSONObject ==
{"ircEvent": "PRIVMSG", "method": "newURI"};
Thanks.
Source: Tips4all
like this:
ReplyDeletedelete myJSONObject.regex;
// or,
delete myJSONObject['regex'];
// or,
var prop = "regex";
delete myJSONObject[prop];
Update: For anyone interested in reading more about it, kangax has written an incredibly in-depth blog post about the delete statement on his blog. Understanding delete. Highly recommended.
var myJSONObject = {"ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*"};
ReplyDeletedelete myJSONObject.regex;
alert ( myJSONObject.regex);
works in FF and IE and I think all others