{}
run-icon
main.js
const resolveName = (fruitname) => { return new Promise((resolve) => { resolve(fruitname); }); }; async function countLetters(fruitList) { let result = ""; await Promise.all( fruitList.map(async (fruit) => { result += fruit + ": " + (await resolveName(fruit)).length + "\n"; // Fix: storing the string into a variable fixes this. // const s = fruit + ": " + (await resolveName(fruit)).length + "\n"; // result += s; }) ); return result; } const arr = ["apple", "banana", "cherry"]; const p = countLetters(arr); p.then((r) => console.log(r));
Output