1

So I have been looking how to remove a record from an array by key, but only found when the key is numberic, the problem is, I don't have a numberic key.

I build an array like this:

var obj = [];

obj.key1 = {name: "John", room: 1234};
obj.key2 = {name: "Jim", room: 1234};

Now the result of obj is

[key1: Object, key2: Object]

Which is exactly what I expect.

Now I am wondering, how would I completely remove key1 from obj? I couldn't find anything about this when the key is alphabetic.

killstreet
  • 1,251
  • 2
  • 15
  • 37

1 Answers1

0

You can do it in very easy way with ES6:

delete(obj["key1"])
OurOwnOwl
  • 334
  • 1
  • 3
  • That's not an ES6 feature, that's old-school JS. By the way, the parentheses aren't required, `delete` isn't a function. – nnnnnn May 26 '17 at 11:23