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 9209315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:48:50+00:00 2026-06-18T00:48:50+00:00

Ive got an array, which I do a few things to but right now

  • 0

Ive got an array, which I do a few things to but right now im trying to divide it between ‘pages’ (more like slides really).

I loop through it using the .each() method, calling this lengthy bit of code to place the info on the right page (just 5 items per page, for now atleast).

Is there a way of simplifying this code?

Ideally so it can go on infinitely:

if (index > 0 && index <= 5) {
    var page = $('#librarian-page-gallery-1');
} else if (index > 5 && index <= 10) {
    var page = $('#librarian-page-gallery-2');
} else if (index > 10 && index <= 15) {
    var page = $('#librarian-page-gallery-3');
} else if (index > 15 && index <= 20) {
    var page = $('#librarian-page-gallery-4');
} else if (index > 20 && index <= 25) {
    var page = $('#librarian-page-gallery-5');
} else if (index > 25 && index <= 30) {
    var page = $('#librarian-page-gallery-6');
} else if (index > 30 && index <= 35) {
    var page = $('#librarian-page-gallery-7');
} else if (index > 35 && index <= 40) {
    var page = $('#librarian-page-gallery-8');
} else if (index > 45 && index <= 50) {
    var page = $('#librarian-page-gallery-9');
}
  • 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-18T00:48:51+00:00Added an answer on June 18, 2026 at 12:48 am

    For example :

    var page = $('#librarian-page-gallery-' + Math.ceil(index/5));
    

    Explanation :

       index/5 builds a float number :
             1 -> 0.2
             4 -> 0.8
             5 -> 1
             6 -> 1.2
    
       and Math.ceil returns the nearest greater or equal integer :
             0.2 -> 1
             0.8 -> 1
             1   -> 1
             1.2 -> 2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got an array which looks like this: array(3) { [title]=> array(3) { [0]=>
I've got an array of files which looks like this: array ( 0 =>
I've got a listbox, which ive bound to an array of strings. The listbox
I've got a multidimensional associative array which includes an elements like $data[status] $data[response][url] $data[entry][0][text]
I've got an object[] array which contains some mixture of builtin types, like Int/Byte/String,
I've got a huge array of values, all or which are much smaller than
I've got an array of strings that looks like this: [noindex,nofollow] or [index, follow,
I've got almost the same question as here . I have an array which
I've got an array of CALayers containing images which can be moved around by
I've got a array of class in which one member is the full path

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.