-1

How can I remove an element from an object list? I wish to remove the element Kristian from someList. For example:

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

I want to achieve:

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

This is similar to Remove Object from Array using JavaScript, but it's implemented differently and the solutions does not work.

Liggliluff
  • 706
  • 1
  • 6
  • 22

3 Answers3

1

You're looking for the delete operator. You can use like so:

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

delete someList["Kristian"];
// OR: delete someList.Kristian;

console.log(someList);
CRice
  • 29,968
  • 4
  • 57
  • 70
1

With delete.

delete someList.Kristian
Miloš Đakonović
  • 3,751
  • 5
  • 35
  • 55
1

Use delete:

const someList = {"Kristian":"2,5,10","John":"1,19,26,96"};
delete(someList.Kristian); // equivalent to   delete someList["Kristian"];
console.log(someList);
connexo
  • 53,704
  • 14
  • 91
  • 128