Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

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

Newbie here! I want to start the loop based on today (ex:"Thursday") and I want to make it stop on "Wednesday"...is that possible? Any help is appreciate! thanks

    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];
  };```
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

For simplicity, you could loop from today to days.length, then again from 0 to 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);

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!