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

  • Home
  • SEARCH
  • 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 4126198
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:58:10+00:00 2026-05-20T23:58:10+00:00

Are there methods by which I can skip a particular number of objects and

  • 0

Are there methods by which I can skip a particular number of objects and take a certain number of objects from an array in javascript?

Basically the pattern I’m looking for is this.

Say I have an array of 8 objects.

First loop:

Return objects at index 0 to 3 from the array.

Second loop:

return objects at index 4 to 7 from the array.

Third loop:

Back to the beginning so return objects at 0 to 3 again.

Ad infinitum…..

I’d love to see a jquery based solution if possible but I’m all open for raw javascript implementations too as I’m eager to learn.

Cheers.

  • 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-05-20T23:58:10+00:00Added an answer on May 20, 2026 at 11:58 pm

    Something like this (plain JavaScript, no need for jQuery ;)):

    var iterator = function(a, n) {
        var current = 0,
            l = a.length;
        return function() {
            end = current + n;
            var part = a.slice(current,end);
            current =  end < l ? end : 0;
            return part;
        };
    };
    

    Then you can call it:

    var next = iterator(arr, 3);
    next(); // gives the first three
    next(); // gives the next three.
    //etc.
    

    DEMO

    It this form, the last iteration might return less elements. You could also extend it and make the function accept a variable step and a different start parameter.

    If you want to wrap around, like if there are only two elements left, to take elements from the beginning, then it gets a bit more sophisticated 😉

    Update: Wrap around would be something like this:

    var iterator = function(a, n) {
        var current = 0,
            l = a.length;
        return function() {
            end = current + n;
            var part = a.slice(current,end);
            if(end > l) {
                end = end % l;
                part = part.concat(a.slice(0, end));
            }
            current = end;
            return part;
        };
    };
    

    DEMO

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

Sidebar

Related Questions

There are numerous Agile software development methods. Which ones have you used in practice
Of the two methods below, which do you prefer to read? Is there another
There are methods to transfer a CGPoint from one UIView to another and from
Is there an existing PL/SQL method which takes a string and returns the same
Which method is preferred? Session.Remove(foo); Session[foo] = null; Is there a difference?
There are too many method for embedding flash in html, which way is the
Are there any methods/systems that you have in place to incentivize your development team
First, I know there are methods off of the generic List<> class already in
What methods are there for automatically getting a stack trace on Unix systems? I
Are there any automatic methods for trimming a path string in .NET? For example:

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.