Currently, I am making an http call to retrieve data from a database. This process involves calling 6 different types individually.
$scope.getAll = function() {
var url = 'http://someurl/';
var allObjects = [];
$scope.types.forEach(element => {
http({
method: 'GET',
url: url + element.name
}).then(function successCallback(response) {
allObjects.push(response.data);
},function errorCallback(response) {
// this doesn't apply to my issue
});
$scope.allObjects = allObjects;
}
This returns a JSON object structured as follows:
[{},
[{ "label":"myLabel",
"types": {
"source":{"url":"some url, "storage":"some storage"}}},
{ "label":"myLabel",
"types": {
"source":{"url":"some url, "storage":"some storage"}}}],[{ more objects}],[{ more objects}],],
All objects have the same structure with nested arrays. My current issue is that during each iteration of the type, it adds it as an array of objects. I want it to be added as a new object instead of an array of objects. For example:
Current Output:
[{}, [{first iteration}], [{second iteration}], [{etc}]]
Desired Output:
[{first iteration}, {second iteration}, {etc}]