Javascript native dictionary class

Source: Internet
Author: User
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.