I would like to store an array of objects however it appears that after the object is stored in the array any reference to it changes the original value.
"use strict"
var array = []
var object = {}
object.animal = "Cow"
array.push(object)
object.animal = "Chicken"
array.push(object)
console.log(array) //[ { animal: 'Chicken' }, { animal: 'Chicken' } ]
Edit: I now understand the objects are stored as references in the array. One way to avoid this is to declare an object for each item as suggested below however how can this be achieved in a loop such as the following:
"use strict"
var array = []
var object = {}
var people = ["Mike Brown", "John Brown", "Mary Sue"]
var fname, sname
people.forEach(function(person) {
[fname, sname] = person.split(" ")
object.name = person
object.fname = fname
object.sname = sname
array.push(object)
})