is there a way to loop an array in "real time" in Javascript or using JQuery? What I mean is to create a loop that reads the array content without caching it before starting the loop, for example if I do this.
var array = [{'hi':0},{'how':1},{'are':2},{'you':3}];
for(var i=0;i < array.length;i++){
console.log(i);
if(i == 2){
array.push({'?':4});
}
}
console.log(array);
The loop will output only 4 values but it already has 5 values before finishing the loop
I would like to also loop the new values inserted while the loop is running.
For more clarification, I need to do this because I am building a web app that creates a queue before submitting data to the server, a loop submits the data in the array but this array can also be updated in the process by other functions
Thanks!
console.log(i, JSON.stringify(array[i]));