Arrays: adding and retrieving objects

by greatCar

JavaScript

//Arrays: adding objects
//https://stackoverflow.com/questions/1168807/how-can-i-add-a-key-value-pair-to-a-javascript-object
var obj={name: 'gary', color: 'blue'};
//alert (obj.color);

var list = [];
list.push(obj);
//alert (list.length);
//alert (list[0].name);

var olist={};
olist[obj.name]=obj;

alert (olist[obj.name].color);