Group array items based on variable javascript

前端 未结 6 1502
囚心锁ツ
囚心锁ツ 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:05

    Good ol' ES5 Array Extras are great.

    var other = {};
    myArray.forEach(function(n, i, ary){
        other[n[2]] = n.slice(0,2);
    });
    

提交回复
热议问题