how to use async await in map in node code example
Example 1: await inside map js
const mapLoop = async _ => {
console.log('Start')
const promises = fruitsToGet.map(async fruit => {
const numFruit = await getNumFruit(fruit)
return numFruit
})
const numFruits = await Promise.all(promises)
console.log(numFruits)
console.log('End')
}
Example 2: js is map async
let obj = {
one: 1,
two: 2,
three: 3
}
obj.map((element, index) => {
// do something
// return result
});
/*
map() is a higher order function (a function that takes another
function as a parameter) and as such is synchronous
*/