[{LanguageMedium: "Sinhala Medium"}, {Subject: "English"}, {Type: "Past"}]
From this array object how to remove the object where object key is "LanguageMedium"
[{LanguageMedium: "Sinhala Medium"}, {Subject: "English"}, {Type: "Past"}]
From this array object how to remove the object where object key is "LanguageMedium"
Iterate over your Object keys using a for..in loop and use the delete
keyword when you get a match.
const obj = { name: 'mary', name: 'john' }
for (const key in obj) {
if (obj.hasOwnProperty(key) && obj[key] === 'mary') {
delete obj[key]
}
}
console.log(obj)
You can use array#find
to iterate through keys in the object and find out the key whose value is Sinhala Medium
. You can get keys using Object.keys()
. Then you can use delete
to remove the key from your object.
var obj = { LanguageMedium: "Sinhala Medium", Subject: "English", Type: "Past" },
key = Object.keys(obj).find(k => obj[k] === 'Sinhala Medium');
delete obj[key];
console.log(obj);
You can iterate through all the keys to match the key to be deleted like the following:
var obj = { LanguageMedium: "Sinhala Medium", Subject: "English", Type: "Past" }
Object.keys(obj).forEach(function(k){
if (obj[k] == 'Sinhala Medium'){
delete obj[k];
}
});
console.log(obj);