Associative Arrays - Javascript -


i trying populate associative array, in dynamic way. have been reading lot of documents unable figure out right way.

the outcome of code be

op{     '0': value1, value2     '128': value3, value4, value 6     '630': value7 } 

this have written , not working

var arr =  []; for(var = 1; <=last ; i++){     var key = rec[i].op;     var op = {};     op[key] = rec[i].description;     arr.push(op); } 

the recent record overwriting previous record.

i think want like:

var op = {}; for(var = 0; < last ; i++) {     var key = rec[i].op;     if (op[key] == undefined)      {         op[key] = [];     }     op[key].push(rec[i].description); } 

Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -