jquery - javascript | Array conversion -


i have array , convert structure.

my array:

["dz|47", "dz|48", "dz|53", "dz|57", "ar|202", "ar|206", "ar|213", "by|484", "by|485", "by|487"] 

and convert into:

{"dz":[47,48,53,57],"ar":[202,206,213],"by":[484,485,487]} 

i'm started write code, but...what next?

$.each(arr, function( index, value ) {     var idx = value.split('|');     //arr2[idx[0]] = arr3; }); 

thanks!

var result = {}; $.each(arr, function( index, value ) {     var idx = value.split('|');     if(!result[idx[0]]){         result[idx[0]] = [];     }     result[idx[0]].push(idx[1]); }); 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -