ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
```js function diPromiseAll(promises){ return new Promise((resolve, reject)=>{ // 参数判断 if(!Array.isArray(promises)){ throw new TypeError("promises must be an array") } let result = [] // 存放结果 let count = 0 // 记录有几个resolved promises.forEach((promise, index) => { promise.then((res)=>{ result[index] = res count++ count === promises.length && resolve(result) // 判断是否已经完成 }, (err)=>{ reject(err) }) }) }) } let p1 = Promise.resolve(1), p2 = Promise.resolve(2), p3 = Promise.resolve(3); diPromiseAll([p1, p2, p3]).then((res)=>{ console.log(res, 'res') }, (err)=>{ console.log(err, 'err') }) ```