Optimize for() loop in arrayForEach -- keep the array length in a variable instead of counting it in each loop