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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:00:15+00:00 2026-05-27T23:00:15+00:00

I am trying to sort objects by there properties. I have a problem on

  • 0

I am trying to sort objects by there properties. I have a problem on Opera and IE with my function. Till now, I have debugged the problem on Opera at this stage:

  1. Open “Opera browser” and press cntr+shift+i. Choose the console.
  2. Pass this code in the console and press shift+enter.

    var DataArray=["Other","Attitude","Attitude","Delivery/timings","General   Performance","Personal Planning","Other"]
    DataArray=DataArray.sort(function(a,b)
    {
        return a<b;
     });
    
    JSON.stringify(DataArray);
    

You should get correct result like this:

[“Personal Planning”,”Other”,”Other”,”General Performance”,”Delivery/timings”,”Attitude”,”Attitude”]

  1. Now change the sort function in this way a>b like this and press enter+shift to exucute it.

    var DataArray=["Other","Attitude","Attitude","Delivery/timings","General   Performance","Personal Planning","Other"]
    DataArray=DataArray.sort(function(a,b)
    {
        return a>b;
    });
    JSON.stringify(DataArray);
    

My result is:

[“Attitude”,”Delivery/timings”,”Attitude”,”General Performance”,”Other”,”Other”,”Personal Planning”]

Note the first, the second and the third value?What is going on?

If you execute this in the console “Attitude”=”Attitude” it returns true…

Any ideas?

Thanks in advance.

EDIT:
And the part with the IE:

CODE:

 var DataArray=['Other','Attitude','Attitude','Delivery/timings','General    Performance','Personal Planning','Other'];

 DataArray=DataArray.sort(function(a,b)
{
     return a<b;
 });

prompt('',DataArray);

Result(correct):Personal Planning,Other,Other,General Performance,Attitude,Attitude,Delivery/timings

CODE:

var DataArray=[‘Other’,’Attitude’,’Attitude’,’Delivery/timings’,’General Performance’,’Personal Planning’,’Other’];

    DataArray=DataArray.sort(function(a,b)
    {
        return a>b;
    });

    prompt('',DataArray);

RESULT (incorrect): Attitude,Attitude,Other,Delivery/timings,General Performance,Other,Personal Planning

SOLUTION:

sortableArray=sortableArray.sort(function(a,b)
                {
                    if(a.Category>b.Category)
                    {
                        return 1;
                    }

                    if(a.Category<b.Category)
                    {
                        return -1;
                    }

                    return 0;

                });

To sort in descending way the data use reverse() function.

Thank you for the help. Especially to @nnnnnn

  • 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-27T23:00:15+00:00Added an answer on May 27, 2026 at 11:00 pm

    This isn’t a problem with any particular browser, it is a problem with not having read the .sort() function documentation. The callback you pass to .sort() is not supposed to return a boolean, it is supposed to return a number that is:

    • negative if a comes before b
    • 0 if a equals b
    • positive if a comes after b
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to sort this array of objects according to (1) depth and (2) weight,
I have this entity - I'm trying to determine the type of its properties
I am trying to sort but there is a nil. How can i get
I'm trying to sort an array that looks like this: var dateGroups = [
We were trying to sort a collection of FileInfo objects in .NET. We implemented
I recently encountered some problems while trying to sort a set of objects. The
I am trying to create a sort of generic xml parser, like this: Part
I am trying to create a 'sort by status' function that shows, for example
This should be self explanatory. I'm trying to implement a distribution sort, and the
I'm trying to call a Sort method that expects a parameter of type IComparer<object>

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.