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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:46:14+00:00 2026-05-28T18:46:14+00:00

Given a JSON resultset such as the following: [ {fooID: 1, fooLabel: one, barID:

  • 0

Given a JSON resultset such as the following:

[ {fooID: 1, fooLabel: "one", barID: 20 barLabel: "twenty"},
  {fooID: 1, fooLabel: "one", barID: 30 barLabel: "thirty"},
  {fooID: 1, fooLabel: "one", barID: 40 barLabel: "forty"},
  {fooID: 2, fooLabel: "two", barID: 500 barLabel: "fivehundred"},
  {fooID: 2, fooLabel: "two", barID: 600 barLabel: "sixhundred"} ]

How could I iterate through this in groups?

Example

<legend>1 - one</legend>
  <div>20 - twenty</div>
  <div>30 - thirty</div>
  <div>40 - forty</div>

<legend>2 - two</legend>
  <div>500 - fivehundred</div>
  <div>600 - sixhundred</div>

Also, it would be preferable that the solution can support more dimensions, even maybe with some minor adjustments, as it’s looking like I’ll have to use this a few times for several applications. And it shouldn’t be an issue, but it may also be good to take into consideration that the results will not always be in order by group such as in the example I provided. It may be ordered 1, 2, 2, 1, 2… etc.

  • 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-28T18:46:15+00:00Added an answer on May 28, 2026 at 6:46 pm

    Sort the Array, then iterate and track which fooID you’re on, and create a new legend when it changes.

    var my_arr = [ {fooID: 1, fooLabel: "one", barID: 20, barLabel: "twenty"},
      {fooID: 1, fooLabel: "one", barID: 30, barLabel: "thirty"},
      {fooID: 1, fooLabel: "one", barID: 40, barLabel: "forty"},
      {fooID: 2, fooLabel: "two", barID: 500, barLabel: "fivehundred"},
      {fooID: 2, fooLabel: "two", barID: 600, barLabel: "sixhundred"} ];
    
    my_arr.sort(function(a,b) {
        return a.fooID > b.fooID;
    });
    
    var curr_group;
    
    $.each(my_arr,function(i,v) {
        if(curr_group !== v.fooID) {
            curr_group = v.fooID;
            $('<legend>',{text:v.fooID + ' - ' + v.fooLabel}).appendTo('body');
        }
        $('<div>',{text:v.barID + ' - ' + v.barLabel}).appendTo('body');
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was wondering, given the following JSON, how I can produce a ResultSet instance,
i have the following JSON response from google maps. I've given two postcodes as
Given the following JSON data: [ { pk: 2, model: corkboard.announcement, fields: { body:
Given the following array of json objects: var items = [ {id:1, parentId:0, name:'item1'},
Given the following JSON, I would like to extract the postal_code (either long_name or
given the following json: { response: { totalProcessingTime: 271.0, resultSets: { products: { firstHit:
i need to parse the JSON data given below. {result:[{bookId:142645,bookpb:MF, bookTs:1328999630000,clipStatus:D,bookDetail:{arrival:1,purchase:1,sold:1}, hierarchies:{categories:[4],events:[]},shopId:769752}, upto sold
I ve data in the JSON format given below,need to populate the slick grid
Given a stream of JSON, how can I read it as XML. I am
Given a boolean list such as [True, False, False, True, False, True] , what

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.