As you know, JavaScript itself does not contain a dictionary object. To facilitate operations, I have set up such a dictionary class and basically imitated it. net System .. collection. generic. attributes and methods of the dictionary class for easy calling.
(1) constructor:
Dictionary ()
(2) attributes:
Comparemode: Compare mode, 0 -- binary 1 -- text
Count: number of items in the dictionary
Throwexception: whether to throw an exception when an error occurs.
(3) method:
Item (key): obtains the value corresponding to the specified key.
Keys (): Get the key Array
Values (): returns an array of values.
Add (Key, value): add the specified key and value to the dictionary.
Batchadd (keys, values): adds the specified array of keys and values to the dictionary. If all the values are successfully added, true is returned. Otherwise, false is returned.
Clear (): Clear all items in the dictionary
Containskey (key): indicates whether the dictionary contains the specified key.
Containsvalue (value): indicates whether the dictionary contains the specified value.
Remove (key): Delete the key specified in the dictionary
Trygetvalue (Key, defaultvalue): obtains the value of the specified key in the dictionary. If the key does not exist, the default value is returned.
Tostring (): returns a string consisting of all keys and values in the dictionary. The format is "comma-separated key list; semicolon-separated value list"
You can click here to download the sourceProgram/Files/xrwang/JavaScript/dictionary. js.