Home > Mobile >  How do I remove property from a JavaScript object?
How do I remove property from a JavaScript object?

Time:03-11

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"
};

CodePudding user response:

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

CodePudding user response:

You can try - delete myObject.regex

  • Related