I have this for loop that I want to increment the year on every cycle, but I'm only getting the last year all repeating multiple times.
for (let i = 0; i < 2; i++) {
this.data.year = new Date().getFullYear() + i;
this.data.noSolar = averageBill * increaseRate;
this.data.withSolar = (contractAmount * .004) + customerCharge;
this.data.saving = (contractAmount * .004 + customerCharge) * 12 - (averageBill * 12);
this.data.check = SREC;
this.data.total = (contractAmount * .004 + customerCharge) * 12 - (averageBill * 12) + SREC;
this.dataSource.push(this.data);
}
The Year in this case 2020 is showing twice. I want something like 2019 and 2020. Its like the variable is being reference multiple times.
this.data) multiple times on the array. Maybe, you can create a new object inside the loop (not usingthis.datafor store the values) and then push this new object insidethis.dataSource