I'm trying to get an array from [getAll].
It must wait for two axios functions, so there are two awaits as you can see.
The problem is, array [A] keep returns nothing but undefined members like [undefined, undefined, undefined, undefined, undefined].
I've checked that [getItem] gets the exact data that what I intended.
So, I think there's something wrong with [getAll]; such as await getItem(Name) but I cannot find out what it is.
[console.log("res1: "+res1);] just prints [res1: undefined].
Thank you for your suggestions.
const getItem = async (Name) => {
await axios
.get(url1+Name)
.then(async (res1) => {
const url3 = url2+res1;
await axios
.get(url3)
.then((res2) => {
console.log(res2.data);
return res2.data;
});
});
};
const getAll = async (Arr) => {
const A=[];
for (const Name of Arr) {
await getItem(Name)
.then((res1) => {
console.log("res1: "+res1);
A.push(res1);
});
}
return A;
}
router.post("/", async (req, res) => {
res.send(await getAll(req.body.Names));
});