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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:42:33+00:00 2026-05-27T00:42:33+00:00

I am interested in how you would sort the following data most effectively with

  • 0

I am interested in how you would sort the following data most effectively with jQuery:

There is a json object which I retrieve from the server:

var data = {/*json-object*/};
$.each(data.level1.sub1, function(){
    if(this.name.length < 2) {
        this.type = "banana";
        itemarray.push(this);
    }
    else {
        this.type = "apple";
        itemarray.push(this);
    }
});

$.each(data.level2.sub1, function(){
    this.type = "kiwi";
    itemarray.push(this);
});

This brings me to the point that I can list what’s in the array (which is typeof object, not a “real” array) by doing this:

if (itemarray.length){
    $.each(itemarray, function(index, value){
      $('#wrapper').append('<li>' + index + ' : ' + value.name + ' * ' + value.type + '</li>');
    });
}  

Result:

0 : abc * apple
1 : a * banana
2 : lala * apple
3 : bcd - Copy * kiwi
4 : okl * banana

Now I would like to sort the array (which is typeof object, again): group by type and sort asc per type. How would you suggest doing that?

  • 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-27T00:42:34+00:00Added an answer on May 27, 2026 at 12:42 am

    Since you’re using the itemarray.push method, I assume that itemarray is a true array. Array objects (note: typeof [] === "object") support a sort() method.

    Use the native Array.sort method, in conjunction with a function, as shown below. This method directly modifies the array.

    var itemarray = [{type:"C"},{type: "B"}]; //Your array looks like this
    
    //ASC result: [{type:"C"}, {type:"B"}]
    itemarray.sort(function(x,y){
        return x.type.localeCompare(y.type);
    });
    //DESC result: [{type:"B"}, {type: "B"}]
    itemarray.sort(function(x,y){
        return y.type.localeCompare(x.type);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would be interested in hearing op opinions from others regarding whether which they
Does anybody know if there are any? I would be interested in a .net
I am interested in writing a trigger that would ignore queries from a specific
I am interested in any library which can do the following: I have a
I am interested in finding out if there exists a program or library which
I'm wondering if there's some sort of runtime mechanism that would observe the queries
I'd be interested to know whether there are programming languages which have shorthand equality
I would be interested to learn about large scale development in Python and especially
I have never seen a way to do this nicely, i would be interested
Does anyone have experience with algorithms for evaluating hypergeometric functions? I would be interested

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.