How do I fix the pending promise in this case?

Viewed 11

The code works as expected:

var a = [1,2,3,4,5,6,7];
async function showArray(arr){
  for (var i = 0; i<arr.length; i++) {
    await showElement(arr[i]);
  }
}
async function showElement(x){
  console.log(x);
  document.getElementById('result').value+=x.toString();
  return new Promise((resolve) => {
    setTimeout(function () {
      resolve("");
    }, 1000);
  });
}
(async()=>{ await showArray(a)})();
<textarea id="result"></textarea>

When I enter the code into my console directly, it says:

There is a Promise <pending>, indicating there is a unresolved promise.

Is this a problem that I need to fix and how can I fix this?

0 Answers
Related