0

I have the following JSON data:

$scope.users = [{ "id": 1, "first_name": "Philip",  "country": "Indonesia" },
                { "id": 2, "first_name": "Judith", "country": "China" },
                { "id": 3, "first_name": "Julie",  "country": "Finland"},
                { "id": 4, "first_name": "Gloria",  "country": "Indonesia"}}];

and I want to add a new property like this:

$scope.users = [{ "id": 1, "first_name": "Philip",  "country": "Indonesia", "new_field":4 },
                { "id": 2, "first_name": "Judith", "country": "China","new_field":4 },
                { "id": 3, "first_name": "Julie",  "country": "Finland","new_field":4},
                { "id": 4, "first_name": "Gloria",  "country": "Indonesia","new_field":4}}];

Is this possible? If yes, how can do this?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Nuran Yüksekce
  • 155
  • 1
  • 9

1 Answers1

3

Use this:

for(var i=0;i<$scope.users.length;i++)
    $scope.users[i].new_field =4;
nAviD
  • 2,784
  • 1
  • 33
  • 54