How to remove a key from an object in Javascript?
Question
I have an object below:1
2
3
4
5var thisIsObject= {
'Cow' : 'Moo',
'Cat' : 'Meow',
'Dog' : 'Bark'
};
I want to remove the key Dog
and its value. What should I do?
Answer
There are three ways to remove a key from an object.1
2
3
4
5
6
7
8
9// Example 1
var key = "Dog";
delete thisIsObject[key];
// Example 2
delete thisIsObject["Dog"];
// Example 3
delete thisIsObject.Dog;
Reference
This is the end of post