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.