Categories
JavaScript Answers

How to remove JSON object key and value with JavaScript?

Spread the love

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: "test@email.com",
  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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *