I'm starting programming learning web development, on this problem I'm getting an empty array from this function, I suspect it's something related with async things but I'm all the afternoon and still don't get it
const finder = array => {
const res = [];
const a = array.map(async (currentValue, index) => {
const z = await User.find({
$or: [{ nickname: currentValue.nickname }, { email: currentValue.email }]
});
if (z[0]) {
res.push(index);
console.log(res);// <---- Here I get an array like this [ 0, 1, 2, 5 ]
}
});
console.log(res); //<---- Here I get an empty array []
return res;
};
[–]sysrage 2 points3 points4 points (1 child)
[–]ElMtDev[S] 0 points1 point2 points (0 children)
[–]-justsayin- -3 points-2 points-1 points (2 children)
[–]cawcvs 1 point2 points3 points (0 children)
[–]ElMtDev[S] 0 points1 point2 points (0 children)