Excellent.  The 4guysfromrolla example is very helpful, thanks.  I've pasted a complete javascript.js file below which allows one to create a dictionary to make calls like the following:

var userDict = new Dictionary();

userDict.Add("smith", "admin");

userDict.Add("jones", "user");

userDict.Delete("jones");

var keys = userDict.Keys

for(var i=0; i<keys.length; i++)

{

alert((keys[i]+": "+userDict.Lookup(keys[i])));

}

Admittedly, the keys array is inefficient, but it's very handy in situations where the dictionary is small.

--Brett

//===========================================================================// Provides a Dictionary object for client-side java scripts//===========================================================================functionLookup(key){return(this[key]);}functionDelete(){for(c=0; c <Delete.arguments.length; c++){this[Delete.arguments[c]]=null;}// Adjust the keys (not terribly efficient)var keys =newArray()for(var i=0; i<this.Keys.length; i++){if(this[this.Keys[i]]!=null)
keys[keys.length]=this.Keys[i];}this.Keys= keys;}functionAdd(){for(c=0; c <Add.arguments.length; c+=2){// Add the propertythis[Add.arguments[c]]=Add.arguments[c+1];// And add it to the keys arraythis.Keys[this.Keys.length]=Add.arguments[c];}}functionDictionary(){this.Add=Add;this.Lookup=Lookup;this.Delete=Delete;this.Keys=newArray();}

JavaScript Dictionary的更多相关文章

  1. javascript Dictionary data structures

    Dictionary常被称为数据字典,是一种用来保存键值对的数据结构,比如我们日常的电话本,就是一个Dictionary.我们通过键(名字),就可以访问到对应的值(电话号码).在C++与java中我们 ...

  2. Hash - a javascript dictionary object.

    Hash,in wikipedia, may relevant to many stuffs. In javascript, hash is a group of name/value pairs w ...

  3. Passing JavaScript Objects to Managed Code

    Silverlight If the target managed property or input parameter is strongly typed (that is, not typed ...

  4. Search API 官方文档 可以用了查看自己的app

    Search API October 24, 2012 - HTTPS is now supported for Search and Lookup requests. Please update y ...

  5. JavaScript基础精华03(String对象,Array对象,循环遍历数组,JS中的Dictionary,Array的简化声明)

    String对象(*) length属性:获取字符串的字符个数.(无论中文字符还是英文字符都算1个字符.) charAt(index)方法:获取指定索引位置的字符.(索引从0开始) indexOf(‘ ...

  6. JavaScript中创建字典对象(dictionary)实例

    这篇文章主要介绍了JavaScript中创建字典对象(dictionary)实例,本文直接给出了实现的源码,并给出了使用示例,需要的朋友可以参考下 对于JavaScript来说,其自身的Array对象 ...

  7. javascript字典数据结构Dictionary实现

    <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat=&qu ...

  8. JavaScript 字典(Dictionary)

    TypeScript方式实现源码 //  set(key,value):向字典中添加新元素. //  remove(key):通过使用键值来从字典中移除键值对应的数据值. //  has(key ...

  9. JavaScript 模拟 Dictionary

    function Dictionary() { var items = {}; //判断是否包含Key值 this.has = function(key) { return key in items; ...

随机推荐

  1. 【python】msgpack使用

    1.存储数据 import msgpack var={'a':'this','b':'is','c':'a test'} with open('file.name','wb') as f: msgpa ...

  2. vscode的go插件安装

    vscode安装go的很多插件都是失败,如下: Installing 5 tools at E:\www\go_project\bin go-symbols guru gorename goretur ...

  3. AC日记——统计和 洛谷 P2068

    统计和 思路: 水题: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 100005 int n,m,tree ...

  4. MSSQL为单独数据库创建登录账户

    如果要为一个数据库创建一个独立的账号需要这个数据库为包含数据库 当前(非包含)的数据库所面临的问题在描述什么是包含数据库之前,先了解一下为什么会出现包含数据库.当前的数据库有一些问题,如下:1.在数据 ...

  5. POJ 1679 The Unique MST 【最小生成树/次小生成树模板】

    The Unique MST Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 22668   Accepted: 8038 D ...

  6. poj 2773欧几里德

    Happy 2006 Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 5957   Accepted: 1833 Descri ...

  7. 【BZOJ 1004】【HNOI 2008】Cards

    http://www.lydsy.com/JudgeOnline/problem.php?id=1004 注意数据给出的m是一个没有单位元的置换群! 用Burnside引理,然后对每个置换群dp一下就 ...

  8. Minimum Height Trees -- LeetCode

    For a undirected graph with tree characteristics, we can choose any node as the root. The result gra ...

  9. [BZOJ 2668] 交换棋子

    Link: BZOJ 2668 传送门 Solution: 重点在于对于每条转移路径:首尾算一次,中间节点算两次 可以一点拆三点,将原流量拆成入流量和出流量 但其实也可以就拆两点,分前后是否是一首尾点 ...

  10. qsc round#2 喵哈哈村的排队(本辣鸡想七想八的,特写此博文给自己一个提醒)

    该oj是qsc自己写的比赛,友情链接:http://qscoj.cn/ 喵哈哈村的排队 发布时间: 2017年2月26日 16:13   最后更新: 2017年2月26日 16:14   时间限制: ...