var arr1 = [1, 3, 5, 7, 9];
var arr2 = [2, 4, 6, 8, 10];

function ajax(status, data, max) {
  return new Promise((resolve, reject) => {
    const time = Math.floor(Math.random() * max);
    setTimeout(() => {
      if(status) {
        resolve(`成功:${data}`);
      } else {
        reject(`失敗:${data}`);
      }
    }, time);
  })
}

function fn() {
  arr1.forEach((item) => {
    ajax(true, item, 10).then((res) => {
      console.log(res);
    })
  });
  arr2.forEach((item) => {
    ajax(true, item, 10).then((res) => {
      console.log(res);
    })
  });
}
fn();

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.