How to get Last passed 7 days Name in Javascript?

Dear Developers,

How can I get Last passed 7 days name in Javascript ? Like, Today is Wednesday I need day name as like as below

['Wednesday','Tuesday','Monday','Sunday','Saturday','Friday','Thursday',] 

Only array of name not time. Thank you

Hey,
Let week array an array of the 7 days name begin with Monday end with Sunday.
Let reverse a function that for a given day name search his index in the week array and construct a new array using this for loop:

let result = [ ] ;
for (let i=0 ; i < 7 ; i++) {
result[i] = week[index-i];
}
return result;
1 Like

thank you . Problem solved.

You are welcome, just check solved box.
Have a nice day.