0
我已經使用lodash模塊如下組合:GROUPBY與Lodash模塊
export class DtoTransactionCategory {
categoryName: String;
totalPrice: number;
}
GROUPBY
import { groupBy} from 'lodash';
let result = groupBy(transactionCategoryList, (c: DtoTransactionCategory) => {
return c.categoryName
});
結果:
所以現在我需要像這樣得到上面的數組(即totalPrice
是group
的sum
):
let myNewArry = [{categoryName:"cat1",totalPrice: 9400},
{categoryName:"cat2",totalPrice: 600}]
你能告訴我如何實現最後一步?我在這裏使用Lodash modules
。
終於拿到了solution.Thank你:) – Sampath