correctly iterate js array