JavaScript - Looping an array in JavaScript