How do I remove a property from a JavaScript object?

Created by nickfLinked to 96.8m issues across 124 teams


To remove a property from an object (mutating the object), you can use the delete statement. For example:

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

Alternatively, you can use object destructuring to create a new object with all the keys of the original except some. For example:

let myObject = { "ircEvent": "PRIVMSG", "method": "newURI", "regex": "^http://.*" }; // assign the key regex to the variable _ indicating it will be unused const {regex: _, ...newObj} = myObject; console.log(newObj); // has no 'regex' key console.log(myObject); // remains unchanged