Categories
JavaScript Answers

How to remove key and value from hash in JavaScript?

Spread the love

Sometimes, we want to remove key and value from hash in JavaScript.

In this article, we’ll look at how to remove key and value from hash in JavaScript.

How to remove key and value from hash in JavaScript?

To remove key and value from hash in JavaScript, we use the delete operator.

For instance, we write

const myHash = {};
myHash["key1"] = { Name: "Object 1" };
myhash["key2"] = null;
myHash["key3"] = { Name: "Object 3" };

delete myHash["key2"];

to create the myHash object.

Then we add some properties to it.

We then remove the key2 property from myHash with

delete myHash["key2"];

Conclusion

To remove key and value from hash in JavaScript, we use the delete operator.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.