remove specific property from json object javascript 1

remove specific property from json object javascript

let value="test";
let myjsonobj = {
      "employeeid": "160915848",
      "firstName": "tet",
      "lastName": "test",
      "email": "test@email.com",
      "country": "Brasil",
      "currentIndustry": "aaaaaaaaaaaaa",
      "otherIndustry": "aaaaaaaaaaaaa",
      "currentOrganization": "test",
      "salary": "1234567"
}
Object.keys(myjsonobj).forEach(function(key){
  if (myjsonobj[key] === value) {
    delete myjsonobj[key];
  }
});
console.log(myjsonobj);

Here is what the above code is Doing:
1. We are creating a JSON object with some key-value pairs.
2. We are iterating over the keys of the JSON object.
3. We are checking if the value of the key is equal to the value we want to remove.
4. If the value is equal to the value we want to remove, we are deleting the key-value pair.
5. We are printing the JSON object.

Output:
{
“employeeid”: “160915848”,
“firstName”: “tet”,
“lastName”: “test”,
“email”: “test@email.com”,
“country”: “Brasil”,
“currentIndustry”: “aaaaaaaaaaaaa”,
“otherIndustry”: “aaaaaaaaaaaaa”,
“salary”: “1234567”
}

Similar Posts