An array can be used to store a collection in JavaScript
var arr = []; // empty array arr.push('A'); arr.push('B'); arr.push('C'); alert(arr.length); // alerts 3 alert(arr[1]); // alerts B (zero based indexing)
Using JavaScript object as a hash table.
Essentially, every java-script object can have multiple properties that are essentially name-value pairs. For example,
var o = { } // empty object o["prop1"] = "A"; // Added property named prop1 with value "A" o["prop2"] = "B"; // Added property named prop2 with value "B" o["prop3"] = "C"; // Added property named prop2 with value "C" alert(o["prop1"]); // alerts A alert(o.prop2); // alerts B - notice alternate syntax alert(o["prop4"]); // alerts undefined - because we are accessing non-existent property if (o["prop3"]) { alert("prop3 exists"); // to check for some property } for (p in o) { // iterate all properties alert(p); // alerts property name alert(o[p]); // alerts property value }