31

I have an array that looks like this:

$scope.quotes =
    [
        {
            'quote': 'foo',
            'author': 'bar',
            'source': 'foobar',
            'first': 'slideout',
        },
        {
            ...
        },
    ]

I'm trying to remove the key-value first: slideout from the array. like this:

delete $scope.quotes[0][first];

I also tried:

delete $scope.quotes[0].first;
Nico Diz
  • 1,387
  • 1
  • 4
  • 19
Himmators
  • 12,918
  • 30
  • 111
  • 198
  • 6
    Your second attempt will work. If it doesn't then there's some other issue. – user2736012 Sep 04 '13 at 15:05
  • 1
    @Kami: That's different. He's trying to remove a key/value pair from a plain object that happens to be in an Array. – user2736012 Sep 04 '13 at 15:07
  • And the first one would work if you had quotes around `first`. E.g., both `delete $scope.quotes[0]['first'];` and `delete $scope.quotes[0].first;` are correct. – T.J. Crowder Sep 04 '13 at 15:07
  • $scope = {}; $scope.quotes = [ { 'quote': 'foo', 'author': 'bar', 'source': 'foobar', 'first': 'slideout', } ]; delete $scope.quotes[0]["first"]; $scope.quotes[0]; // What you have should work. – Layke Sep 04 '13 at 15:08

0 Answers0