I had a code that processes a huge JSON array in a "for" loop.
for(var i = 0; item = arr[i]; i++) {
//PROCESS item
}
The issue was with a Firefox browser. It shows a warning dialog that script is running too long. The following code was the solution
//not precise code example, but it's kind of.
delay(arr, 0);
function delay(arr, num) {
//process array by parts with 50 elements in each part
for(var i = 1; i <= 50; i++) {
//PROCESS arr[num];
num += i;
}
if(num < arr.length) {
setTimeout(function() { delay(arr, num); }, 100);
}
}
I wondering if there is a more fabulous way to workaround complete UI freeze and make Firefox to don't show script debug dialog. Please advise. Thanks