Looking to rearrange an array in a specific order:
Starting with the initial array:
const weekDaysArray = ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su'];
containing the days of the week in sequence, then obtaining a variable
const firstWeekday = Object.values(formattedReadsByDay)[0].dayOfWeek;
which holds a day of the week, let's say We
for this example.
When it returns We
, I want to change the array to:
weekDaysArray = ['We', 'Th', 'Fr', 'Sa', 'Su', 'Mo', 'Tu'];
I attempted
weekDaysArray [...weekDays.slice(-1), ...weekDays.slice(0, -1)]
but it didn't yield the desired result. Any suggestions?