console.log(getWeekByDate('2017-05-05'));
// ["2017-04-29", "2017-04-30", "2017-05-01", "2017-05-02", "2017-05-03", "2017-05-04", "2017-05-05"]
function getWeekByDate(date) {
let dd = new Date(date);
let week = [dealDate(dd)];
for(let i = 0; i < 6; i++) {
dd.setDate(dd.getDate() - 1);
week.push(dealDate(dd));
}
return week.reverse();
}
function dealDate(date) {
return date.getFullYear() + '-' + addZero(date.getMonth() + 1) + '-' + addZero(date.getDate());
}
function addZero(num) {
return num < 10 ? '0' + num : num;
}