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 a stream of JSON, how can I read it as XML. I am
Given the URL (single line): http://test.example.com/dir/subdir/file.html How can I extract the following parts using
Given the following mapping <class name=com.domain.Season table=cm.pub.jsn_mstr> <id name=seasonCode column=season_code length=1/> <property name=name type=string
Given a contract such as: [ServiceContract] public interface IService { [OperationContract] [WebGet(UriTemplate = GetData/{id}.{format})]
Given the simple JSON below, how can I use jQuery to append each result
I want to convert the given data to JSON format ... please help me
Problem : for a given query i try to parse the json from the
My Gae application retrieves JSON data from a third party site; given an ID

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.