0

i have this code :

const delay = () => new Promise((resolve) => setTimeout(resolve, 2000));

async function displayScore(score) {
  await delay();
  console.log(score);
}

async function processScores(scores) {
  forEach(scores, async (score) => {
    await displayScore(score);
  });
}

processScores([1, 2, 3, 4]);

Why am I getting the message that forEach is not defined?

Jake White
  • 90
  • 1
  • 8

1 Answers1

0

You are getting an error forEach is not defined because there is no such function called forEach(). There is, though, a method Array.prototype.forEach():

scores.forEach(async score => {
...
});