How can I use lodash/underscore to sort by multiple nested fields?

前端 未结 7 1154
情话喂你
情话喂你 2021-02-03 21:51

I want to do something like this:

var data = [
    {
        sortData: {a: \'a\', b: 2}
    },
    {
        sortData: {a: \'a\', b: 1}
    },
    {
        sort         


        
7条回答
  •  攒了一身酷
    2021-02-03 22:29

    With ES6 easy syntax and lodash

    sortBy(item.sortData, (item) => (-item.a), (item) => (-item.b))
    

提交回复
热议问题