自定义一个forEach
static customForeach = async (arr, callback) => {
const length = arr.length;
const Obj = Object(arr);
let k = 0;
while (k < length) {
if (k in Obj) {
const kValue = Obj[k];
await callback(kValue, k, Obj);
}
k++;
}
};
用的时候像下面这样调用即可:
await customForeach(someArray,async (element)=>{
await xxx();
});