我有一個數組:Lodash ORDERBY對象
const names = [{name: 'a', equal: 3},
{name: 'b', equal: 2},
{name: 'c', equal: 2},
{name: 'd', equal: 3},
{name: 'a1', equal: 1}]
我運行_.groupBy(名稱, '等於'),結果獲得:
{1: [{equal: 1, name: 'a1'}],
2: [{equal: 2, name: 'b'}, {equal: 2, name: 'c'}],
3: [{equal: 3, name: 'a'}, {equal: 3, name: 'd'}]}
但在這裏按名稱排序消失。如何在此對象中按名稱排序?
更新
我想:
{3: [{equal: 3, name: 'a'}, {equal: 3, name: 'd'}],
1: [{equal: 1, name: 'a1'}],
2: [{equal: 2, name: 'b'}, {equal: 2, name: 'c'}]}
所以要排序相等,然後通過名稱爲對象進行排序以相同的平等嗎? –
是的,我想得到:{3:[{equal:3,name:'a'},{equal:3,name:'d'}], 1:[{equal:1,name:'a1 '}], 2:[{equal:2,name:'b'},{equal:2,name:'c'}]} – user5671335
對象有沒有順序或在即將到來的JS中,順序是帶整數值。 –