var person = {
name: "Harry",
age: 16,
gender: "Male"
};
// Deleting a property completely
delete person.age;
alert(person.age); // Outputs: undefined
console.log(person); // Prints: {name: "Harry", gender: "Male"}
delete myObject.regex;
// OR
delete myObject['regex'];
let myObject = {
"ircEvent": "PRIVMSG",
"method": "newURI",
"regex": "^http://.*"
};
const {regex, ...newObj} = myObject;
console.log(newObj); // has no 'regex' key
console.log(myObject); // remains unchanged
const names = {
father: "Johnny",
brother: "Billy",
sister: "Sandy"
}
delete names.father
// { brother: "Billy", sister: "Sandy" }
delete names["father"]
// { brother: "Billy", sister: "Sandy" }
/*The JavaScript delete operator removes a property from an object;
*/
const Employee = {
firstname: 'John',
lastname: 'Doe'
};
console.log(Employee.firstname);
// expected output: "John"
delete Employee.firstname;
console.log(Employee.firstname);
// expected output: undefined
const { a, ...rest } = { a: 1, b: 2, c: 3 };
var myObject = {
"ircEvent": "PRIVMSG",
"method": "newURI",
"regex": "^http://.*"
};
delete myObject.regex;
console.log(myObject);