Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (9.5k points)

Below is the object I’ve: 

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');

1 Answer

0 votes
by (19.7k points)

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]; 

// Example 2

delete thisIsObject["Cow"];

// Example 3

delete thisIsObject.Cow;

Interested in Java? Check out this Java Certification by Intellipaat.




 

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
0 answers

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...