[{LanguageMedium: "Sinhala Medium"}, {Subject: "English"}, {Type: "Past"}]
从这个数组对象中如何删除对象键所在的对象" LanguageMedium"
答案 0 :(得分:0)
使用for..in循环迭代您的对象键,并在获得匹配时使用delete
关键字。
const obj = { name: 'mary', name: 'john' }
for (const key in obj) {
if (obj.hasOwnProperty(key) && obj[key] === 'mary') {
delete obj[key]
}
}
console.log(obj)

答案 1 :(得分:0)
您可以使用array#find
遍历对象中的键,找出值为Sinhala Medium
的键。您可以使用Object.keys()
获取密钥。然后,您可以使用delete
从对象中删除密钥。
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);

答案 2 :(得分:0)
您可以迭代所有键以匹配要删除的键,如下所示:
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);