Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9089157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T22:04:51+00:00 2026-06-16T22:04:51+00:00

I need to loop through an array using the for clause, but starting at

  • 0

I need to loop through an array using the for clause, but starting at some specific index and just to a maximum of iterations.

The code below does the task, but it looks awful to me: it’s there a better way?

  var offset = 10, max = 5;
  for (var i = 0; (i + offset) < data.length && i < max; i++) {
    doSomething(data[i + offset]);
  }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T22:04:53+00:00Added an answer on June 16, 2026 at 10:04 pm

    If I am understanding your question correctly you would just need to initialize i to the offset.

    var offset = 10, max = 5 + offset;
    for (var i = offset; i < data.length && i < max; i++) {
        doSomething(data[i]);
    }
    

    edit: didn’t understand the max at first.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to loop through a set of 2-dimensional array of hidden input fields
i have the following code ..i need to loop through end of the file
Okay so this is a bit complex but I need to loop through this
I need to loop through type RECORD items by key/index, like I can do
Let's say I need to run a for loop through an array where I
Using Javascript, I'm trying to loop through an array and execute a function with
I want to access the value of thumbnail using Smarty but I need some
I need to loop through the items as an array within the SimpleXMLElement Object
I need to loop through a List of Dictionaries List<Dictionary<string,string>> to populate a DataTable.
I need to loop through each day of the week (monday tues...) and compare

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.