1

How do I remove an entry, such as [2] from below?

var object = {};
object[0] = true;
object[1] = true;
object[2] = true;
Hard worker
  • 3,916
  • 5
  • 44
  • 73
  • possible duplicate of [How to remove a property from a javascript object](http://stackoverflow.com/questions/208105/how-to-remove-a-property-from-a-javascript-object) – brenjt Nov 01 '12 at 16:32

2 Answers2

6

This will work:

delete object["2"]

I would suggest you don't use "object" as your variable name. "object" is a reserved word.

Also, see this question: how-to-remove-a-property-from-a-javascript-object

EDIT:

Actually "object" is not on the list of reserved words. But "Object" (capital "O") does have a meaning in JavaScript. So I would discourage using that name anyway.

Community
  • 1
  • 1
jfrej
  • 4,548
  • 29
  • 36
1

To remove object properties, use delete, like this:

delete object[2];
Nelson
  • 49,283
  • 8
  • 68
  • 81