For loop API request, how to know which one of the current requests is successful after success

after the circular request, the es6 syntax is not supported, and it is not passed to the server json format. The API will only return the success status without any identification. How to know which array element is passed successfully at the front end. Thank you

var arr = [{
  gymAddr: "00000000",
  trainingActionId: "123",
  deviceId: "1"
}, {
  gymAddr: "00000000",
  trainingActionId: "123",
  deviceId: "2"
}, {
  gymAddr: "00000000",
  trainingActionId: "123",
  deviceId: "3"
}]

for (var i = 0; i < arr.length; iPP) {
  wx.request({
    url: "https://localhost:8080/trainingRecord/single",
    data: arr[i],
    method: "POST",
    header: {
      "content-type": "application/x-www-form-urlencoded"
    },
    success: function(res) {
      console.log("res", res);
      console.log(this)
    }
  })
}
Apr.02,2021

for (var i = 0; i < arr.length; iPP) {
    (function(){
        var _i=i;
        wx.request({
        ...
        })
    })()
}

var arr = [{
  gymAddr: "00000000",
  trainingActionId: "123",
  deviceId: "1"
}, {
  gymAddr: "00000000",
  trainingActionId: "123",
  deviceId: "2"
}, {
  gymAddr: "00000000",
  trainingActionId: "123",
  deviceId: "3"
}]

for (let i = 0; i < arr.length; iPP) {
  wx.request({
    url: "https://localhost:8080/trainingRecord/single",
    data: arr[i],
    method: 'POST',
    header: {
      'content-type': 'application/x-www-form-urlencoded'
    },
    success: function(res) {
      console.log('res', res);
      console.log(this)
      if(res.status == 200){
          console.log(i)
      }
    }
  })
}

for (let i = 0; i < arr.length; iPP) { // 
  request({
    url: "https://localhost:8080/trainingRecord/single",
    data: arr[i],
    method: 'POST',
    header: {
      'content-type': 'application/x-www-form-urlencoded'
    },
    success: function(res) {
      console.log('res', res, i);
      console.log(this)
    }
  })
}

or:

for (var i = 0; i < arr.length; iPP) {
 // 
  (function(i){
    request({
        url: "https://localhost:8080/trainingRecord/single",
        data: arr[i],
        method: 'POST',
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        success: function(res) {
          console.log('res', res, i);
          console.log(this)
        }
    })
  })(i)
}

closure or use the index in forEach as the index

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3f40d-2b1bf.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3f40d-2b1bf.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?