Dictionary object (Object/JScript)

A name-value collection object created by the Active X facilities.

Availability:

JScript - 3.0
Internet Explorer - 4.0
JavaScript syntax:IEmyDictionary = new ActiveXObject("Scripting.Dictionary");
Object properties:Count
Object methods:Add(), Exists(), Item(), Items(), Key(), Keys(), Remove(), RemoveAll()

A dictionary is a special kind of collection or array which allows you to access items using name and value pairs. This is functionally similar to using associative name indexing on a JavaScript array, so although this is not generally available, its fundamental usefulness is already provided in the native JavaScript implementation.

The Dictionary object provided by JScript and Active X, has a few extra properties and methods to help manage the contents of the dictionary. These could be simulated fairly easily and added to the Array prototype to create your own portable Dictionary-like object.

Warnings:

Example code:

   // Create a new dictionary
   var myDictionary = new ActiveXObject("Scripting.Dictionary");
   // Store some items in the dictionary
   // (Melting Points of fats/waxes)
   myDictionary.Add("Butter",       "28");
   myDictionary.Add("Lard",         "36");
   myDictionary.Add("MuttonTallow", "44");
   myDictionary.Add("Beeswax",      "61");
   myDictionary.Add("Stearin",      "71.6");
   myDictionary.Add("ParaffinWax",  "38");
   // Display one item if it exists
   if(myDictionary.Exists("ParaffinWax"))
   {
   document.write("Paraffin Wax melts at ");
   document.write(myDictionary.Item("ParaffinWax"));
   document.write(" degrees Centigrade.");
   }
   // Remove an item
   if(myDictionary.Exists("Stearin"))
   {
   myDictionary.Remove("Stearin");
   }
   // Change an item and its key
   if(myDictionary.Exists("MuttonTallow"))
   {
   myDictionary.Item("MuttonTallow") = "40";
   myDictionary.Key("MuttonTallow") = "BeefTallow";
   }
   // List all the items
   myArray = (new VBArray(myDictionary.Keys())).toArray();
   for(myEnum=0; myEnum<myArray.length; myEnum++)
   {
   document.write("Key value: ");
   document.write(myArray[myEnum]);
   document.write("Item value: ");
   document.write(myDictionary.Item(myArray[myEnum]));
   document.write("<BR>");
   }
   // Now discard the items in the array
   myDictionary.RemoveAll();

See also:ActiveX, ActiveXObject object

PropertyJavaScriptJScriptNIEOperaNESECMADOMCSSHTMLNotes
Count n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/aReadOnly

MethodJavaScriptJScriptNIEOperaNESECMADOMCSSHTMLNotes
Add() n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a-
Exists() n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a-
Item() n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/aWarning
Items() n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a-
Key() n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a-
Keys() n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/aWarning
Remove() n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a-
RemoveAll() n/a3.0 3.0 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a-