How to group an array of objects by key

后端 未结 24 3012
后悔当初
后悔当初 2020-11-21 05:13

Does anyone know of a (lodash if possible too) way to group an array of objects by an object key then create a new array of objects based on the grouping? For example, I hav

24条回答
  •  我寻月下人不归
    2020-11-21 05:34

    I made a benchmark to test the performance of each solution that don't use external libraries.

    JSBen.ch

    The reduce() option, posted by @Nina Scholz seems to be the optimal one.

提交回复
热议问题