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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:22:14+00:00 2026-06-04T17:22:14+00:00

Say I am being provided a json object that looks like this: {someList: [{id:

  • 0

Say I am being provided a json object that looks like this:

{"someList": [{"id": "21154859" },{"id": "21154865" },{"id": "21154856" },{"id": "21154870" }]}

I want to find out what the index number of the current ‘someList’ item I am on.
I have the someList item id and it is represented by the var aid and equals : 21154856.

I have created a function like so:

$.getJSON( url, function( data ) {
var jsonLength = data.someList.length;
for ( i=1; i <= jsonLength; i++ ){
        chx = data.someList[i].id;
        if(chx === aid){
            var currentidno = Number(i) + 1;
            $('#page').html('').append(currentidno + ' of ' + jsonLength);
            break;
        }
        }
});

When I set this up it works fine and gives me a result like this:
3 of 4

But it feels inefficient and I wonder how it would perform if there were thousands of possibilities. Can someone weigh in on whether or not this ia the best way to achieve what I want to do and either verify or deny the assumption that this is a good way to accomplish the task?

  • 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-04T17:22:16+00:00Added an answer on June 4, 2026 at 5:22 pm

    No. The loop is just the way to go. However, if you need to do that search often on many elements, it might be efficient to build an index (or just deliver the JSON as an Array of numbers at once, if there are no other properties):

    var indexArray = data.someList.map(function(o){return o.id;});
    var currentidno = indexArray.indexOf(aid) + 1;
    

    Or you could with indexing by object properties, instead of an array:

    someValues = {"21154859":{index:0},"21154865":{index:1},"21154856":{index:2},"21154870":{index:3},... }; 
    // no order needed!
    var currentidno = someValues[aid].index + 1;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

say i have a nvarchar field in my database that looks like this 1,
A simple example: Let's say I have one alias being sourced somewhere as: alias
Is there a method to detect what APIs are being called? Say I wanted
Situation: I've got a SVN repository with lets say 100 revisions, rev. 100 being
Say I have a couple of basic objects like so: [Serializable] public class Base
Say I write this: from subprocessing import Popen, STDOUT, PIPE p = Popen([myproc], stderr=STDOUT,
Say I have real, dimension(0:100) :: realResults and I want to iterate over realResults
I have an abstract class A that define abstract methods. This means that, for
NOTE : My problem is NOT that my links are not being replaced. But,
Lets say that I purchased a new domain (somedomain.com) from a domain registar and

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.