守着一只汪
并发调用asyncfunctionmain(){constlist=[1,2,3,4]Promise.all(list.map(id=>fetch(`http://api?id=${id}`))).then(results=>{...}))}//或者用asyncasyncfunctionmain(){constlist=[1,2,3,4]constresults=awaitPromise.all(list.map(id=>fetch(`http://api?id=${id}`)),)...}逐个调用,等前面一个调用返回在调用下一个functionmain(){constlist=[1,2,3,4]list.reduce((promise,id)=>promise.then(results=>fetch(`http://api?id=${id}`).then(result=>[...results,result]),),Promise.resolve([]),).then((results)=>{...})}//或者用asyncasyncfunctionmain(){constlist=[1,2,3,4]letresults=[]for(constidoflist){constresult=awaitfetch(`http://api?id=${id}`)results.push(result)}...}