Javascript 是否可以向现有JSON数据添加新属性?
我有以下JSON数据:Javascript 是否可以向现有JSON数据添加新属性?,javascript,arrays,json,Javascript,Arrays,Json,我有以下JSON数据: $scope.users = [{ "id": 1, "first_name": "Philip", "country": "Indonesia" }, { "id": 2, "first_name": "Judith", "country": "China" }, { "id": 3, "first_name": "Julie", "country": "Finland"},
$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"}}];
我想添加一个新属性,如下所示:
$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}}];
这可能吗?如果是,如何做到这一点?使用以下方法:
for(var i=0;i<$scope.users.length;i++)
$scope.users[i].new_field =4;
对于(var i=0;i使用以下方法:
for(var i=0;i<$scope.users.length;i++)
$scope.users[i].new_field =4;
for(var i=0;icast数据到动态列表。只需添加一个新的动态属性。将数据转换到动态列表。只需添加一个新的动态属性。