如何从对象列表中删除元素?
我希望从Kristian
中删除元素someList
。例如:
someList = {"Kristian":"2,5,10",
"John":"1,19,26,96"};
我要实现:
someList = {"John":"1,19,26,96"};
这与Remove Object from Array using JavaScript类似,但实现方式不同,解决方案不起作用。
答案 0 :(得分:1)
您正在寻找delete operator。您可以这样使用:
const someList = {
"Kristian": "2,5,10",
"John": "1,19,26,96"
};
delete someList["Kristian"];
// OR: delete someList.Kristian;
console.log(someList);
答案 1 :(得分:1)
使用delete
。
delete someList.Kristian
答案 2 :(得分:1)
使用删除:
const someList = {"Kristian":"2,5,10","John":"1,19,26,96"};
delete(someList.Kristian); // equivalent to delete someList["Kristian"];
console.log(someList);