Get next object in an array by property value?
<h2>Background</h2>

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

<pre><code>// 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
// ...
</code></pre>

<p>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 <code>selected</code> property is set to true, for the selected object in the array.</p>

<p>I'm using grep to return all of the selected Users.</p>

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

<p>Here's an example of the data returned:</p>

<pre><code>[ 
  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 
  }
]
</code></pre>

<h2>Question</h2>

<p>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?</p>

<p>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)?</p>

<p><a href="http://jsfiddle.net/MatthewKeefe/2VdUZ/" rel="nofollow">JSFiddle</a></p>
