The delete
operator allows you to remove a property from an object.
The following examples all do the same thing.
// Example 1
var key = "Cow";
delete thisIsObject[key];
// Example 2
delete thisIsObject["Cow"];
// Example 3
delete thisIsObject.Cow;
let animals = {
'Cow': 'Moo',
'Cat': 'Meow',
'Dog': 'Bark'
};
delete animals.Cow;
delete animals['Dog'];
console.log(animals);
If you’re interested, read Understanding Delete for an in-depth explanation.