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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:10:03+00:00 2026-05-26T02:10:03+00:00

In my web app I have an object which is built from a JSON

  • 0

In my web app I have an object which is built from a JSON string passed from a server. A typical JSON string might look like this:

{
  "_id": {
    "$binary": "4x3tC1oTBkyvbu43rQj0EQ==",
    "$type": "03"
  },
  "title": "Sony FW31 Lit 973.pdf",
  "tags": [
    {
      "category": "Machine",
      "text": "Cold Planers"
    },
    {
      "category": "Attachments",
      "text": "Blades"
    }
  ]
}
,
{
  "_id": {
    "$binary": "s/Svg2CjSUWB1QGJ7e3QeA==",
    "$type": "03"
  },
  "title": "Sony FW31 Lit 974.pdf",
  "tags": [
    {
      "category": "Machine",
      "text": "Cold Planers"
    },
    {
      "category": "Attachments",
      "text": "Blades"
    }
  ]
},... and lots more items...

There might be thousands of objects in the JSON string. I can happily parse the JSON using JSON.parse(). This creates an object that I can iterate over using the following javascript:

var soughtKey='4x3tC1oTBkyvbu43rQj0EQ==';
for (var ii = 0; ii < itemlist.length; ii++) {
    var item = itemlist[ii];
    if (item._id$binary==soughtKey){
        doSomething(item);
    }
}

This seems rather inefficient. I’d rather do this:

doSomething(itemlist[soughtKey]);

But presumably to do this I’d need to convert my top-level object into some sort of key-indexable array? I assume there is no way to gain access to specific itemlist items using their id values?

Assuming not, what is the most efficient way to convert my top-level itemlist object into an array of objects where all the properties of the original items are still accessible via the dot notation, and any item can be directly accessed via its id? (I know each nested item will have an _id, but I won’t know the rest of the structure in advance). And are there any performance trade-offs between converting the JSON object to the array versus leaving it as-is and using my inefficient loop?

Thanks very much.

  • 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-26T02:10:04+00:00Added an answer on May 26, 2026 at 2:10 am

    In order to locate something by value you have to loop over the object and test the values at the individual keys. There’s no way to avoid this.

    In order to build a lookup object you have to loop over the entire object one time and collect values from the first object and store them in the second object. This is intensive up front, but will equate to savings later if you have to repeatedly find things by the values you’d like to use as keys.

    So the question is, do you do this once (you’re after a specific piece of the JSON return) or does this happen repeatedly in your page (you use part of the object in section A of the code, then another part of the object in section B, etc)? If the former, it’s probably not worth the added overhead to loop through the entire object and create a lookup. If the latter, then you’ll probably benefit in the long run by creating an easier way to retrieve your desired information by appropriate keys.

    Creating your lookup object might go something like this:

    var byIds = {};
    
    for (var ii = 0, l = items.length; ii < l; ++ii) {
      var item = items[ii];
    
      byIds[item._id.$binary] = {
        'title': item['title'],
        'tags': item['tags']
      };
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an object which contains models for my ASP.NET MVC web app. The
I have a web-app-database 3 tier server setup. Web requests data from app, and
I have a web app which connects to a server using a TCP connection
In the context of a web app, I have a server which sends or
In the web.xml of my web app I have configured the server as following:
I have a feature in my web app like I have to send mails
I have a asp.net 2.0 web app which calls a long running stored proc
Hi I'm developing a small web app in which I have and embed video
We have a web app in which a request for a long running or
I have a web app which displays a list of emails that need to

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.