Why do I get a different array?

后端 未结 1 1166
[愿得一人]
[愿得一人] 2021-01-28 18:31

Good day. I have problem with give different arrays;

my code next:

setInterval(function() {

var TestName = [];
var requests = [];
TestName.push(\'0\');         


        
相关标签:
1条回答
  • 2021-01-28 18:44

    The reason your array is different each time is that you are running asynchronous requests and then populating from the callback. Each time you do this your requests happen to be finishing in different order and therefore populating the array in a different order.

    You must not rely on async request callbacks being called at any particular point within your execution, they can be called at any time, depending on when the response decides to come back.

    0 讨论(0)
提交回复
热议问题