I am getting the data like this
[
{ "id":1,
"name":"john"
},
{ "id":2,
"name":"ram"
}
]
I want to change the above data to below
"array":
[
{ "id":1,
"name":"john"
},
{ "id":2,
"name":"ram"
}
]
I am getting the data like this
[
{ "id":1,
"name":"john"
},
{ "id":2,
"name":"ram"
}
]
I want to change the above data to below
"array":
[
{ "id":1,
"name":"john"
},
{ "id":2,
"name":"ram"
}
]
The way to format your object in JavaScript would be something like this:
{
"array": [
{ "id":1, "name":"john" },
{ "id":2, "name":"ram" }
]
{
I did not get this statement I want to do this question using angular only how can we achieve the output like that in angular as it's all about structuring/wrapping the JSON data. Hence, I added the solution in angular.js snippet below.
Demo (Angular) :
function ArrayController($scope) {
const resData = [{
"id":1,
"name":"john"
}, {
"id":2,
"name":"ram"
}];
$scope.data = {
array: resData
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.1.1/angular.min.js"></script>
<div ng-app ng-controller="ArrayController">
<div>{{ data }}</div>
</div>