I am trying to push a few objects into an array through a for loop. Although, in that for loop I would like the name of the object to be the current iteration of the for loop. The for loop displayed below runs twice, therefore the Name variable for the first object should be 1 and the name for the second object should be 2. But, in this case for whatever reason, both objects in this array return a Name value of 2. Does anyone know why this would happen?
var ThisArray = [];
var ThisObj = {};
for (var x = 1; x <= 2; x++) {
ThisObj.Name = x;
ThisArray.push(ThisObj);
}
console.log(ThisArray);