0

looks like there is a bug in chrome.

When trying to sort array of objects with the following code

var list = [
    {Name: "Data1", pos: 35},
    {Name: "dProduct", pos: 35},
    {Name: "dSampleDeliveryDate", pos: 35},
    {Name: "dAnalysisDate", pos: 35},
    {Name: "dDestinationName", pos: 35},
    {Name: "Data3", pos: 35},
    {Name: "dRequirementRemarks", pos: 35},
    {Name: "dAutoRemarks", pos: 35},
    {Name: "dManualRemarks", pos: 35},
    {Name: "Data13", pos: 35},
    {Name: "dSignatures", pos: 35},
]

var sortFunc = function(a, b) {
    return 0;
}

list.sort(sortFunc);

console.log(list);

the result should be the same list due to return 0 in sort function, but in log

{Name: "Data3", pos: 35}
{Name: "Data1", pos: 35}
{Name: "dSampleDeliveryDate", pos: 35}
{Name: "dAnalysisDate", pos: 35}
{Name: "dDestinationName", pos: 35}
{Name: "dProduct", pos: 35}
{Name: "dRequirementRemarks", pos: 35}
{Name: "dAutoRemarks", pos: 35}
{Name: "dManualRemarks", pos: 35}
{Name: "Data13", pos: 35}
{Name: "dSignatures", pos: 35}

In all the rest browsers results are correctly the same.

1 Answers1

0

This is not a bug. From MDN:

The sort is not necessarily stable.

So equal elements can be in any relative order in the result, they don't have to preserve their original order.

Barmar
  • 741,623
  • 53
  • 500
  • 612