Javascript sort custom comparator function - sorting a sorted array

前端 未结 5 743
你的背包
你的背包 2021-02-03 22:23

I have an array of objects of the following form:

arr[0] = { \'item1\' : 1234, \'item2\' : \'a string\' };

I sort it first by \'item1\'

5条回答
  •  滥情空心
    2021-02-03 23:12

    You can just import type-comparator with npm and then use queue to do the chaining:

    const comparator = queue([
        map(x => x.item1, asc),
        map(x => x.item2, asc)
    ]);
    arr.sort(comparator);
    

提交回复
热议问题