SOURCE

//参数列表
const list = [];
for (let i = 0; i < 100; ++i) {
    list.push(i);
}
function PromiseForEach(arr, cb) {
    let realResult = []
    let result = Promise.resolve()
    arr.forEach((a, index) => {
        result = result.then(() => {
            return cb(a).then((res) => {
                realResult.push(res)
            })
        })
    })

    return result.then(() => {
        return realResult
    })
}

PromiseForEach(list, (number) => {

    return new Promise((resolve, reject) => {
        //异步请求,在请求的最后返回
        setTimeout(() => {
            console.log("number", number);
            return resolve(number);
        }, 1000);
    })

}).then((data) => {
    console.log("成功");
    console.log(data);
}).catch((err) => {
    console.log("失败");
    console.log(err)
}); 
console 命令行工具 X clear

                    
>
console