array problem in javascript : Logic -


i have 2 arrays of equal length.

 array1 = {a,a,a,b,b,b,b,b,c,c,c,c,c,c,d,d,d,d,e,e} array2 = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20}  want create object.  var obj = { 'a': {1,2,3}  'b': {4,5,6,7,8} 'c': {9,10,11,12,13,14}  .....  ..... } 

can me logic.

var group = {};  if (array1.length == array2.length) {   (var i=0, j=array1.length; i<j; i++) {     if ( !(array1[i] in group) ) group[array1[i]] = [];     group[array1[i]].push(array2[i]);   } } 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -