break array of objects into separate arrays based on a property

后端 未结 7 1176
太阳男子
太阳男子 2020-12-01 07:10

Say I have an array like this:

var arr = [
    {type:\"orange\", title:\"First\"},
    {type:\"orange\", title:\"Second\"},
    {type:\"banana\", title:\"Thi         


        
7条回答
  •  天涯浪人
    2020-12-01 07:38

    JQuery and Underscore are both options to use.

    Underscore's groupBy does exactly what you need.

    _.groupBy(arr, "type")
    

提交回复
热议问题