I've made this jsfiddle and I can't explain why the following doesn't result in an array of 5 objects all with different id properties:
var arr = ["1", "2", "3", "4", "5"];
var clone = {"id": "0", "name":"Matthew"};
var arrObj = [];
var idArr = [];
while((a=arr.pop()) != null){
clone.id = a;
console.log(clone);
arrObj.push(clone);
}
console.log(arrObj);
What I end up getting is the following in my console:
Object {id: "5", name: "Matthew"} (index):28
Object {id: "4", name: "Matthew"} (index):28
Object {id: "3", name: "Matthew"} (index):28
Object {id: "2", name: "Matthew"} (index):28
Object {id: "1", name: "Matthew"} (index):28
[Object, Object, Object, Object, Object]
When I open each of the 5 cloned objects they all have an "id" value of "1"
Why is this?