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. linux命令(24):find命令

    1.命令格式: find pathname -options [-print -exec -ok ...] 2.命令功能: 用于在文件树种查找文件,并作出相应的处理 3.命令参数: pathname: ...

  2. HDU-5351

    MZL's Border Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  3. Next Permutation&&Permutation Sequence

    Next Permutation Implement next permutation, which rearranges numbers into the lexicographically nex ...

  4. SQL Server 连接字符串和身份验证 学习

    SQL Server .NET Data Provider 连接字符串包含一个由一些属性名/值对组成的集合.每一个属性/值对都由分号隔开.          PropertyName1=Value1; ...

  5. ELK系列--logstash无法启动

    1.logstash无法启动,提示bind address   原因:   1)配置目录下存在多个配置文件,而logstash会加载所有conf格式的文件   解决方案:删除不必要的,保留一个conf ...

  6. 2t3ik、ddgs与Linux异常文件下载处理

    异常1: 这样的邮件发生了两周了,烦得很.进入服务器,用top看来下进程. 解决办法 首先 kill 相关PID 进入/tmp/   删除相关文件 rm -rf 2t3ik相关文件 不给相关文件修改权 ...

  7. 简单的WSGI server

    参考:https://ruslanspivak.com/lsbaws-part1/ 简单的WSGI server server程序 webserver.py # Tested with Python ...

  8. Interllij IDEA 使用Git工具

    1.git简介 git是目前流行的分布式版本管理系统.它拥有两套版本库,本地库和远程库,在不进行合并和删除之类的操作时这两套版本库互不影响.也因此其近乎所有的操作都是本地执行,所以在断网的情况下任然可 ...

  9. BotBuilder Nodejs示例查看

    关于Bot Framework知识,可以参考<Nodejs Bot学习> 本文是根据bot framework官方示例<https://github.com/Microsoft/Bo ...

  10. 2017江苏省省赛 Roads(全局最小割)

    Roads 时间限制: 2 Sec  内存限制: 256 MB提交: 6  解决: 2[提交][状态][讨论版] 题目描述 In ICPCCamp, there are n towns conveni ...