Given an object:
let myObject = { "ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*" };
How do I remove the property regex to end up with the following myObject?
let myObject = { "ircEvent": "PRIVMSG", "method": "newURI" };
To remove a property from an object (mutating the object), you can do it by using the
deletekeyword, like this:Demo
For anyone interested in reading more about it, Stack Overflow user kangax has written an incredibly in-depth blog post about the
deletestatement on their blog, Understanding delete. It is highly recommended.If you’d like a new object with all the keys of the original except some, you could use destructuring.
Demo