I have been attempting to populate an array with objects, but for some reason, the array is not filling correctly. The last value seems to be set in all positions of the array. Below is the code snippet I am using:
var matrixprice = 5;
var qualifiedDate = '2019-10-01';
var today = new Date();
var qDate = new Date(qualifiedDate);
var nextDay = qDate;
var myObject = new Object();
var myArray = [];
var dailybonus = matrixprice * 0.03;
var full_bonus = matrixprice * 2;
var i = 0;
while (i <= full_bonus) {
nextDay.setDate(nextDay.getDate() + 1);
i += dailybonus;
myObject.title = '$' + i;
myObject.start = nextDay;
myArray.push(myObject);
}
var myString = JSON.stringify(myArray);
console.log(myString);
The issue I'm facing is that the resulting array contains only one value repeated across all positions like this:
[{"title":"$100.5","start":"2020-01-03T18:50:23.000Z"}, {"title":"$100.5","start":"2020-01-03T18:50:23.000Z"},{"title":"$100.5","start":"2020-01-03T18:50:23.000Z"},{"title":"$100.5","start":"2020-01-03T18:50:23.000Z"},{"title":"$100.5","start":"2020-01-03T18:50:23.000Z"},{"title":"$100.5","start":"2020-01-03T18:50:23.000Z"}]
Your help is greatly appreciated!