'How do I remove property from a JavaScript object?

ay I create an object as follows:

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

How should I remove the property regex to end up with new myObject as follows?

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


Solution 1:[1]

You can try - delete myObject.regex

Solution 2:[2]

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

delete myObject.regex;
console.log(myObject);

The delete operator deletes both the value of the property and the property itself. You can check in https://www.w3schools.com/howto/howto_js_remove_property_object.asp

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Aditya Goel
Solution 2 Yahfi Ilham