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

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

1
  • This question is edited as there is an change in the question Commented Mar 7, 2018 at 11:09

3 Answers 3

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)

Sign up to request clarification or add additional context in comments.

Comments

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);

Comments

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);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.