Sometimes, we want to remove JSON object key and value with JavaScript
In this article, we’ll look at how to remove JSON object key and value with JavaScript.
How to remove JSON object key and value with JavaScript?
To remove JSON object key and value with JavaScript, we use the delete operator.
For instance, we write
const myObject = {
employeeid: "888888",
firstName: "tet",
lastName: "test",
email: "[email protected]",
country: "Brasil",
currentIndustry: "aaaaaaaaaaaaa",
otherIndustry: "aaaaaaaaaaaaa",
currentOrganization: "test",
salary: "1234567",
};
delete myObject["currentIndustry"];
console.log(myObject);
to remove the currentIndustry property from myObject with delete myObject["currentIndustry"];.
Conclusion
To remove JSON object key and value with JavaScript, we use the delete operator.