i have a array that contains a object with two values, like this:
[
{
brand: app1,
url: https://myhost.com/api
},
{
brand: app2,
url: https://otherapi.com/api
}
]
I'am using axios.all to made a get request over all urls, and I iterate it with a map, like this:
const getData= axios.all(stuffData.map((item) => axios.get(item.url)))
.then(res => console.log(res.data)
The thing is, how can I pass the second param in the array when i make the map to interate all axios requests? I also need pass the key "brand".
Thanks
CodePudding user response:
Use this:
Promise.all(stuffData.map(async (item) => ({
data: await axios.get(item.url).data,
brand: item.brand
}))).then((data) => {
data.forEach(item=> console.log(item))
})