Group array items based on variable javascript

前端 未结 6 1503
囚心锁ツ
囚心锁ツ 2020-12-31 11:18

I have an array that is created dynamic from an xml document looking something like this:

myArray[0] = [1,The Melting Pot,A]
myArray[1] = [5,Mama\'s Mexican         


        
6条回答
  •  忘掉有多难
    2020-12-31 12:21

    Try groupBy function offered by http://underscorejs.org/#groupBy

    _.groupBy([1.3, 2.1, 2.4], function(num){ return Math.floor(num); });
    
    Result => {1: [1.3], 2: [2.1, 2.4]}
    

提交回复
热议问题