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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:47:49+00:00 2026-05-30T16:47:49+00:00

I have my json data as follows: var Data = [{Name:a1,ID:b1, year:2011}, {Name:a2, ID:b2,

  • 0

I have my json data as follows:

var Data = [{"Name":"a1","ID":"b1", "year":"2011"}, 
{"Name":"a2", "ID":"b2", "year":"2012"}, 
{"Name":"a3", "ID":"b3", "year":"2012"},
{"Name":"a4", "ID":"b4", "year":"2010"}];

I need to display the data as follows,

2012
a2   b2
a3   b3

2011
a1   b1

2010
a4   b4

This is what I have tried: To get unique values

var uniqueGroups = {};
            $.each(Data, function () {
uniqueGroups[this.year] = this.year;
});

 $.each(uniqueGroups, function (g) {
                resultsdiv.append('<p>' + g +'</p>' );
                $.each(json.Data, function (i, memDetails) {
                    if (memDetails.year == g) {
                        resultsdiv.append('<div>' + memDetails.Name + memDetails.ID +'</div>');
                    }
                });
            });

This prints out the results but in ascending order, But I would require it to be in descending order. How can I approach this? (Even if I sort the json on the server, it is returning in ascending order)

  • 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-30T16:47:50+00:00Added an answer on May 30, 2026 at 4:47 pm
    var uniqueGroups = [];
    $.each(json.Data, function () {
        var year = parseInt(this.year);
        if (uniqueGroups.indexOf(year) < 0) {
            uniqueGroups.push(year);
        };
    });
    uniqueGroups.sort(function(x, y) { return x < y; });
    
    $.each(uniqueGroups, function (index, year) {
        resultsdiv.append('<p>' + year.toString() + '</p>');
        $.each(Data, function (i, memDetails) {
            if (memDetails.year == year.toString()) {
                resultsdiv.append('<div>' + memDetails.Name + memDetails.ID + '</div>');
            }
        });
    });
    ​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JSON data like this: { hello: { first:firstvalue, second:secondvalue }, hello2:
I have a website where an ajax call will get some Json data from
I have a web service that queries data from this json file, but I
my json string is as follows: var data = [{first:3,second:1},{first:5,second:5},{first:7,second:1}]; Now i am calling
I have the follow data returned via JSON {rows:[{Date:07/10/2011,Value:1206,Action:Drink}, {Date:07/11/2011,Value:2288,Action:Pie}, {Date:07/12/2011,Value:1070,Action:Drink}, {Date:07/13/2011,Value:1535,Action:Beer}, {Date:07/14/2011,Value:1721,Action:Drink}], page:1,total:1,records:5}
I use json data with jquery... I have filepaths in json and i am
I have a problem accessing JSON data. I'm new to JSON and jquery so
I have a controller that is called with AJAX (sends JSON data), so I
I have to serialize & desserialize json data. if the data type was XSD,
I have an issue regarding to auto populating a select dropdown from jQuery/JSON data

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.