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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T06:28:21+00:00 2026-05-23T06:28:21+00:00

I have a json object array. I want to search the array and for

  • 0

I have a json object array. I want to search the array and for each object, create a list of ‘services’ that is a comma-seperated list of all the keys which have a value of “yes”.
The list of json objects with the services list is then displayed in html using jquery’s each.

Its a large json file so I want to do it as efficiently as possible.

I already have the object’s properties being accessed through jQuery’s each (ie, obj.name)
— so I think it should be possible to filter the services listed for each object using
jQuery’s filter, and then display the key if the value is yes.

But it seems like a more efficient option would probably be to create a new javascript array, join the services with a value of yes and then add that variable to the html being
appended.

Im not sure which would be faster and so far havent been very successful at either… so any advice and examples would be very helpful.

Here’s what the json array looks like:

[
 {"name":"name1",
  "service1":"y",
  "service2":"y",
  "service3":"n",
 },

 {"name":"name2",
  "service1":"n",
  "service2":"y",
  "service3":"n",
 },
];
  • 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-23T06:28:21+00:00Added an answer on May 23, 2026 at 6:28 am

    First off, delete trailing commas. Internet Explorer gets really, really confused by them. Anyway, I assume you don’t want to “search” the array when you say “for each value”; you want to iterate through the array and parse it into a more usable list. The first method I’d suggest is just passing what you want as the array you desire, but if that’s not an option, what you’re looking for is some variant of this, which should be fairly efficient (jsFiddle example):

    var json = [
      {"name":"name1", "service1":"y", "service2":"y", "service3":"n"},
      {"name":"name2", "service1":"n", "service2":"y", "service3":"n"}
    ];
    var parsed = {};
    
    for (var i = 0, iLen = json.length; i < iLen; i++) {
      // Assuming all we need are the name and a list
      var name;
      var list = [];
    
      for (var key in json[i]) {
        var value = json[i][key];
    
        // We need to hold on to the name or any services with value "y"        
        if (key === "name") {
          name = value;
        } else if (value === "y") {
          list.push(key);
        }
      }
    
      // Add them to the parsed array however you'd like
      // I'm assuming you want to just list them in plain text
      parsed[name] = list.join(", ");
    }
    
    // List them on the web page
    for (var key in parsed) {
      document.write(key + ": " + parsed[key] + "<br>");
    }
    

    That way you wind up with a display to the visitor of the services available and still keep an array around for further use if necessary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have a JSON object that is a 2-dimentional array and I need
I want to create a new object and assign some properties for each array
I have a request that returns a JSON object with a single property which
Example: I have the following JSON object. {currentVersion : 10.0, folders : [], services
I have an iPhone app with an array of objects that I want to
In C# i have an array of Calendar objects each Calendar object has an
I have a JSON array with ActiveRecord objects. These objects can be reconstructed using
I have created a json object from ruby with cobravsmongoose, however the attributes have
say I have the following json object; {'fname':'john', 'lname':'Locke'} and the following text boxes
I have two JSON objects with the same structure and I want to concat

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.