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

  • Home
  • SEARCH
  • 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 3782092
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T11:02:04+00:00 2026-05-19T11:02:04+00:00

I noticed IE9 sort order is changing elements order when comparison function returns 0

  • 0

I noticed IE9 sort order is changing elements order when comparison function returns 0.

See:

var myarray=[
    {id:1,val:0},
    {id:2,val:0},
    {id:3,val:7},
    {id:4,val:41}
];
myarray.sort(function(a,b){return a.val - b.val});

for(var i in myarray)
{
    console.log(myarray[i].id);
}

Current stable versions of Chrome, Firefox, Opera and Safari got the following output: 1 2 3 4.

Same output for IE7 and IE8.

IE9 output is: 2 1 3 4

Why? Is that normal?

  • 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-19T11:02:04+00:00Added an answer on May 19, 2026 at 11:02 am

    From MDC (emphasis mine):

    If compareFunction(a, b) returns 0, leave a and b unchanged with respect to each other, but sorted with respect to all different elements. [Note: the ECMAscript standard does not guarantee this behaviour], and thus not all browsers (e.g. Mozilla versions dating back to at least 2003) respect this.

    In my experience, only Chrome/Firefox get this right. Opera 11’s behavior for me is .. not well defined.

    E.g., using sort to move all zeroes to the top of the array:

    [1, 0, 3, 0, 5, 0, 2].sort(function (a, b) { return b === 0 && 1 || 0;});
    
    • Chromium 10: [0, 0, 0, 1, 3, 5, 2]
    • Firefox 4: [0, 0, 0, 1, 3, 5, 2]
    • Opera 11: [0, 0, 0, 2, 1, 5, 3] <- does not maintain order of non-zeroes
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a project that adds elements to an AutoCad drawing. I noticed that
It appears to me that IE9 does not recognize cellspacing. Anybody noticed the same
I noticed that IE9 renders downsized images in a very low quality: if I
Has anyone else noticed that IE9's standard implementation of CSS box-shadow differs from other
Now that IE9 has come out, I noticed that the IE=EmulateIE7 trick also affects
I noticed that GoogleToolbarNotifier.exe cannot be killed from Process Explorer. It returns Access Denied.
I noticed that Google maps is providing directions in my local language (hungarian) when
I noticed that you can call Queue.Synchronize to get a thread-safe queue object, but
I noticed that my Designer.vb file of one of my forms has a lot
I noticed in another post, someone had done something like: double d = 3.1415;

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.