Back
Below is the object I’ve:
var thisIsObject= { 'Cow' : 'Moo', 'Cat' : 'Meow', 'Dog' : 'Bark'};
var thisIsObject= {
'Cow' : 'Moo',
'Cat' : 'Meow',
'Dog' : 'Bark'
};
Can anyone tell me how to implement a function that removes by key like below?
removeFromObjectByKey('Cow');
You can use the ‘delete’ operator, which helps you to remove a property from an object. See the code below:
// Example 1
var key = "Cow";delete thisIsObject[key];
var key = "Cow";
delete thisIsObject[key];
// Example 2
delete thisIsObject["Cow"];
// Example 3
delete thisIsObject.Cow;
Interested in Java? Check out this Java Certification by Intellipaat.
31k questions
32.8k answers
501 comments
693 users