How can I transform an array of objects called 'urls' into an array where each object is mapped accordingly, considering the properties 'name' and 'url' within each object?
let urls = [{
"name": "regions",
"url": context + "ip/region/getAllRegions.do?query="
},
{
"name": "sub regions",
"url": "context + 'ip/region/getAllSubRegions.do"
},
];
this.axiosData = urls.map(t => {
axios.get(t.url)
.then(res => {
if (res.data.responseCode == 1) {
return res.data.payload;
} else {
toastr.error("error retrieving " + t.name, "Failure");
}
})
.catch(err => {
console.log(err);
});
});
In order to convert 'axiosData' from a single array to an array of arrays containing objects, whereby res.data.payload contains an array of objects, define axiosData in the data section property of Vue instance.
The resulting axiosData structure would resemble something like this:
[[{
"id": 8,
"name_en": "Rangpur",
}, {
"id": 9,
"name_en": "Sylhet",
}, {
"id": 10,
"name_en": "Mymensingh",
}],
[{
"another_id": 8,
}, {
"another_id": 9,
}, {
"another_id": 10,
}]]