async groupBy (sortData:OrderItem[]) { const arr = (array: OrderItem[], f: Function) => { const groups: { [key:string]: OrderItem[], } = {} array.forEach(function (o) { const group = JSON.stringify(f(o)); groups[group] = groups[group] || []; groups[group].push(o); }); return Object.keys(groups).map(function (group) { return groups[group]; }); } const sorted = arr(sortData, (item: OrderItem) => { return item.orderId; }); return sorted; }
标签:arr,group,数组,ts,return,分组,groups,OrderItem,const From: https://www.cnblogs.com/yang-1023/p/16621330.html