Sorting an array of objects in Chrome

后端 未结 3 1627
傲寒
傲寒 2020-12-01 09:21

EDIT: As noted by kennytm below and after investigating myself, according to the ECMA spec, when two objects are determined to be equal in a custom sort, JavaScript is

3条回答
  •  日久生厌
    2020-12-01 10:09

    May be you know it already but you can use an array to sort on multiple columns and avoid this bug:

    var customSort = function(a,b) {
        return [a.a, a.b] > [b.a, b.b] ? 1:-1;
    }
    

提交回复
热议问题