SOURCE

function getWeekLastDate(date){
    var index = date.getDay();
    console.log(date.getDay());
    let diff = index;
    if(index > 0 && index <= 5)
    {
        diff = 5 - index;
    } else if(index === 0){
        diff = 5;
    }
    date.setDate(date.getDate()+diff)
    console.log(date)
}

getWeekLastDate(new Date('2021-10-31'))
console 命令行工具 X clear

                    
>
console