Skip to content

字节:输出以下代码运行结果,为什么?如果希望每隔 1s 输出一个结果,应该如何改造?注意不可改动 square 方法#69

@sisterAn

Description

@sisterAn
constlist=[1,2,3]constsquare=num=>{returnnewPromise((resolve,reject)=>{setTimeout(()=>{resolve(num*num)},1000)})}functiontest(){list.forEach(asyncx=>{constres=awaitsquare(x)console.log(res)})}test()

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions