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

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -