36

I presume this is an odd question but I have to ask..

If I have a js object that looks like this:

$scope.obj1 = {
    "name":"John",
    "number":"Eleven",
    "color":"Red"
}

Is there a way to remove an entire property? without re-assigning values to a new object.. So if I want to get rid of "number":"Eleven", I would like the object to look like this...

$scope.obj1 = {
    "name":"John",
    "color":"Red"
}

Thanks!

JAAulde
  • 18,787
  • 5
  • 52
  • 61
GRowing
  • 4,389
  • 12
  • 51
  • 74
  • 1
    *"If I have a json object [...]"* [There is no such thing as a "JSON object"](http://benalman.com/news/2010/03/theres-no-such-thing-as-a-json/). – Felix Kling May 12 '14 at 22:09
  • I am aware of that... I wrote this small tidbit as a string to ask a question... thanks anyways. – GRowing May 12 '14 at 23:23

1 Answers1

10

JavaScript has a delete operator:

delete $scope.obj1.number
zzzzBov
  • 167,057
  • 51
  • 314
  • 358