使用JavaScript从对象列表中删除元素

时间:2018-08-31 22:15:09

标签: javascript list

如何从对象列表中删除元素? 我希望从Kristian中删除元素someList。例如:

someList = {"Kristian":"2,5,10",
             "John":"1,19,26,96"};

我要实现:

someList = {"John":"1,19,26,96"};

这与Remove Object from Array using JavaScript类似,但实现方式不同,解决方案不起作用。

3 个答案:

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