Create javascript iterator function for array obj