javascript - Mixing Index Array with "Associative Array" -
since need access items sometime index , sometime code. idea mix integer index string index? note code, index, amount of items never changes after data loaded. i'm thinking of doing this, same object pushed , set hashtable. function datainformation(code, datavalue) { this.code = code; this.datavalue = datavalue; } var datalist = []; function filldatalist() { addnewdata(new datainformation("c1", 111)); addnewdata(new datainformation("c2", 222)); addnewdata(new datainformation("c3", 333)); } function addnewdata(newdata) { datalist.push(newdata); datalist[newdata.code] = newdata; } then able access object either: datalist[0].datavalue datalist["c1"].datavalue before used loop find item. function finditembycode(code) { (var = 0; < datalist.length; i++) { if (datalist[i].code == code) { return datalist[i]; } } return null; } finditembycode("c1")