当前位置: 代码迷 >> JavaScript >> javascript分组(还算高效率)
  详细解决方案

javascript分组(还算高效率)

热度:123   发布时间:2012-11-25 11:44:31.0
javascript分组(还算高效)
var arr =  [
        	['aaa',1,2,3],
        	['bbb',2,4,'c'],
        	['ccc',2,35,6],
        	['aaa',45,14,78],
        	['bbb',77,74,11],
        	['aaa',14,1425,14],
        	['ccc',14,14,18]
	      ];

var gro = {};

for(var i=0;i<arr.length;i++){
	if(gro[arr[i][0]]){
		gro[arr[i][0]].push(arr[i]);
	}else{
		gro[arr[i][0]] = [];
		gro[arr[i][0]].push(arr[i]);
	}
}

alert(JSON.stringify(gro));
  相关解决方案