Does anybody know why this filterData map function is
returning an array of arrays instead of array of objects ?
I am using a map() function inside another map() so basically I am trying to iterate first map function over the big array and afterwards run it inside the child array.
I just want to return an simple object only wit the data that I select in the second map object.
function apiCall() {
const promises = urls.map((url) => axios.get(url, { headers }));
Promise.all(promises).then((responses) => {
let data = [];
let filterData;
responses.forEach((response) => {
data = data.concat(response.data);
filterData = data.map((nested0) =>
nested0.childNested.map((nested1) => {
return {
id: nested0.id,
name: nested0.serve,
date: nested1.name
};
})
)
});
});
}
and this is the json structure that I want to iterate, map cannot run into the second array from object.
[
{
"Id": "tryuk34io98i",
"src": "planet",
"gwt": {
"gwtId": 918,
"name": "Request"
},
"serve": "Transit1",
"childNested": [
{
"name": "xxl",
"version": "001",
"description": "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
"solved": {
"id": "tik",
"name": "face",
"isOn": "false"
},
"externalRef": [
{
"type": "eight",
"uri": "git"
},
{
"type": "two",
"uri": "git"
}
],
"project": {
"name": "InProgress",
"version": "1",
"active": true
},
"used": 0,
"internal": false
}
],
"affe": 0
},
{
"Id": "987ytrdfghv",
"src": "Space",
"gwt": {
"gwt": 918,
"name": "Request"
},
"serve": "Transit",
"childNested": [
{
"name": "xxs",
"version": "02",
"description": "Nullam sed lorem nec sem lobortis porta. Morbi vitae lorem velit.",
"solved": {
"id": "tok",
"name": "back face",
"isOn": true
},
"externalRef": [
{
"type": "one",
"uri": "http"
},
{
"type": "two",
"uri": "http"
}
],
"project": {
"name": "Fail",
"version": "1.1",
"active": false
},
"used": 0,
"internal": false
}
],
"affe": 0
}
]
.map()always returns an array:data.map((nested0) => nested0.childNested.map(...))o.O.reduce()or.flatMap()or.flat()