I'm encountering an issue where my code is returning an object that gets converted to an array, but during this process, the original descriptive keys like url, id, and name are lost and replaced with numerical indices (0, 1, 2, etc.).
How can I maintain these descriptive keys in the final array output? My desired array structure should resemble the following:
[
"description": "blah blah blah"
"telephone": "101",
"id": "bedfordshire",
"name": "Bedfordshire Police"
]
.ts code:
fetchForceDetail(){
return this.http
.get<ForceDetail[]>('https://data.police.uk/api/forces/' + bedfordshire)
.pipe(map(responseData => {
const detailArray = [];
for (const key in responseData) {
if (responseData.hasOwnProperty(key))
detailArray.push(responseData[key])
}
return detailArray;
}))
.subscribe(forcedetails => {
console.log(forcedetails);
});
}