When I tried to compare the difference in runtime between iteration of the forward and reverse loops in server-side JavaScript (SSJS), a (weird) problem arose. Although this code example
var i,n=9999; var arr=new Array(n); for (i=0;i<n;i++) arr[i]=i;
working fine, the following code
var i,n=10000; // changed n from 9999 to 10000 var arr=new Array(n); for (i=0;i<n;i++) arr[i]=i; // WORKS i=n; while (i--) arr[i]=i; // THROWS ArrayIndexOutOfBoundsException
throws an ArrayIndexOutOfBoundsException for the reverse iteration. The inverse while loop works fine as long as the length of the array is less than 10000 . Can someone tell me what is going on here?
source share