I'm trying to get the previous 8 Sundays in JavaScript. Not only did this not work, but it looks very clunky. I feel something with arrays would work cleaner. What did I do wrong?
var now = new Date();
var today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
var lastSunday = new Date(today.setDate(today.getDate() - today.getDay()));
lastSunday = lastSunday.format("mm/dd/yyyy");
var lastSunday2 = new Date(today.setDate(today.getDate() - today.getDay() - 7));
lastSunday2 = lastSunday2.format("mm/dd/yyyy");
var lastSunday3 = new Date(today.setDate(today.getDate() - today.getDay() - 14));
lastSunday3 = lastSunday3.format("mm/dd/yyyy");
var lastSunday4 = new Date(today.setDate(today.getDate() - today.getDay() - 21));
lastSunday4 = lastSunday4.format("mm/dd/yyyy");
var lastSunday5 = new Date(today.setDate(today.getDate() - today.getDay() - 28));
lastSunday5 = lastSunday5.format("mm/dd/yyyy");
var lastSunday6 = new Date(today.setDate(today.getDate() - today.getDay() - 35));
lastSunday6 = lastSunday6.format("mm/dd/yyyy");
var lastSunday7 = new Date(today.setDate(today.getDate() - today.getDay() - 42));
lastSunday7 = lastSunday7.format("mm/dd/yyyy");
var lastSunday8 = new Date(today.setDate(today.getDate() - today.getDay() - 49));
lastSunday8 = lastSunday8.format("mm/dd/yyyy");
console.log(lastSunday8); //this gives 06/25/2017 Obviously not what I wanted.