There are two alternatives I have for executing a piece of code. The code basically resets all the values in three arrays. Two of them are int arrays and one is boolean.
Choice 1
for (i = 0; i < array1.length; i++)
array1[i] = 0;
for (i = 0; i < array2.length; i++)
array2[i] = 0;
for (i = 0; i < array3.length; i++)
array3[i] = false;
Choice 2
int limit = <assign the greatest of the array lengths>
for (i = 0; i < limit; i++)
{
if (i < array1.length)
array1[i] = 0;
if (i < array2.length)
array2[i] = 0;
if (i < array3.length)
array3[i] = false;
}
Which of these would be faster? Given that the arrays can have varying lengths and have no relationship with each other.
There is a real good discussion here. The answer listed first explains quiet well what arrays actually mean in javascript. For those interested to check it out!