-1
[{LanguageMedium: "Sinhala Medium"}, {Subject: "English"}, {Type: "Past"}]

From this array object how to remove the object where object key is "LanguageMedium"

3 Answers3

0

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)
nicholaswmin
  • 21,686
  • 15
  • 91
  • 167
0

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);
Hassan Imam
  • 21,956
  • 5
  • 41
  • 51
0

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);
Mamun
  • 66,969
  • 9
  • 47
  • 59