How to iterate through an array of objects in JavaScript