Looping through an array in javaScript