array 如何从中间开始循环并使其在开始之前的元素处结束?

array how can I start a loop from the middle and make it end at the element before the start?

这里是新手!我想根据今天(例如:“星期四”)开始循环,我想让它在“星期三”停止......这可能吗?任何帮助表示赞赏!谢谢

    let days = [
      "Sunday",
      "Monday",
      "Tuesday",
      "Wednesday",
      "Thursday",
      "Friday",
      "Saturday",
    ];
    let date = new Date();
    let today = date.getDay();
    let result = [];
    

    for (let i = today; i < days.length; i++) {
      result.push(days[i]);
    }

    return result[index];
  };```

为简单起见,您可以从 today 循环到 days.length,然后再从 0 循环到 today

let days = [
      "Sunday",
      "Monday",
      "Tuesday",
      "Wednesday",
      "Thursday",
      "Friday",
      "Saturday",
    ];
    let date = new Date();
    let today = date.getDay();
    let result = [];
    

    for (let i = today; i < days.length; i++) {
      result.push(days[i]);
    }
    for (let i = 0; i < today; i++) {
      result.push(days[i]);
    }

    console.log(result);