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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:49:36+00:00 2026-06-06T04:49:36+00:00

Background I have an array of objects (Users) defined and set as follows: //

  • 0

Background

I have an array of objects (Users) defined and set as follows:

// object definition
function Users()
{
  this.Id = null;
  this.Name = null;
  this.FirstName = null;
  this.LastName = null;
  this.IsActive = null;
  this.Title = null;
  this.index = null;
  this.selected = null;
}

// object array
var AllUsers = [];

// ...
// an ajax call retrieves the Users and adds them to the AllUsers array
// ...

The index value is set on each User to the order in which they were retrieved. Once the Users are retrieved, they can then be selected, one-by-one, and moved from a list to a table on the page. Upon select, the selected property is set to true, for the selected object in the array.

I’m using grep to return all of the selected Users.

var SelectedUsers = $.grep(AllUsers,function(obj){
  return obj["selected"] == true;
});

Here’s an example of the data returned:

[ 
  Object { 
    Id="00540000001AbCdEFG", 
    Name="First Last1", 
    FirstName="First", 
    LastName="Last1", 
    Title="Title", 
    index=56, 
    selected=true 
  },
  Object { 
    Id="00540000001AbChIJK", 
    Name="First Last2", 
    FirstName="First", 
    LastName="Last2", 
    Title="Title", 
    index=12, 
    selected=true 
  },
  Object { 
    Id="00540000001AbClMNO", 
    Name="First Last3", 
    FirstName="First", 
    LastName="Last3", 
    Title="Title", 
    index=92, 
    selected=true 
  }
]

Question

I want to be able to page through the data, and to do that, I need to be able to get the next and previous selected User by index. How can I do that?

If, for example, I open the first Selected User (index=56), in the table, how can I get the User with the next index (the third Selected User with index=92)?

JSFiddle

  • 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-06T04:49:37+00:00Added an answer on June 6, 2026 at 4:49 am

    Fiddle:
    http://jsfiddle.net/iambriansreed/KEXwM/

    JavaScript Added:

    SelectedUsers.sort(function(a,b){
          return a.index == b.index ? 0 : (a.index < b.index ? -1 : 1)});
    

    If you didn’t want to modify the original SelectedUsers array then define the sort to a new variable:

    var SortedSelectedUsers = SelectedUsers.slice(0);
    SortedSelectedUsers.sort(function(a,b){
          return a.index == b.index ? 0 : (a.index < b.index ? -1 : 1)});
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background: I have this with rollup query defined in MySQL: SELECT case TRIM(company) when
Background I have an Array of data in a result object returned by an
Background: I have an N-length array of positive random numbers that are certain to
Background I have a custom collection that is binded to the datagridview this.datagridview.DataSource =
I have an array of objects which will be the basis for a certain
Quick background, I am using Netbeans to develop this (I don't have much experience
I've been using Object as a way to have a generic associative array (map/dictionary)
I have an array of a custom JavaScript object which has a property named
Background: Suppose I have the following obviously-incorrect PHP: try{ $vtest = ''; print(array_pop($vtest)); }catch(Exception
Background I have a dimension table that has a single record for each day.

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.