乐趣区

关于javascript:使用Promiseasync-await每隔1秒打印数组元素

      function sleep(interval) {
        return new Promise(resolve =>
          setTimeout(() => resolve(interval), 1000)
        );
      }
      async function stepPrint(n) {for (let i = 0; i <= n; i++) {console.log(i);
          await sleep(i * 10000);
        }
      }
      stepPrint(5);
退出移动版