Answer the question
In order to leave comments, you need to log in
How to call fetch on each item when recursively iterating over tree objects and get a modified array as an output?
There is an array
const data = [
{
id: 1122029,
children: [
{
id: 1122028,
children: [
{
id: 1122027,
children: []
},
{
id: 1122022,
children: []
},
{
id: 1122022,
children: []
},
]
}
]
}
];
const fetchOptions (id) => {
return fetch(`url${id}`).then(result => {
/* тут создаю объект на основе result и возвращаю его*/
return data
})
}
const addingOptions = (array) => {
array.forEach(item => {
fetchOptions(item.id);
if (item.children.length) {
addingOptions(item.children)
}
})
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question