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. CodeForces 450B

    B. Jzzhu and Sequences time limit per test 1 second memory limit per test 256 megabytes input standa ...

  2. 【DUBBO】dubbo的Router接口

    Router服务路由, 根据路由规则从多个Invoker中选出一个子集AbstractDirectory是所有目录服务实现的上层抽象, 它在list列举出所有invokers后,会在通过Router服 ...

  3. gulp-babel,es6转es5

    npm install --save-dev gulp-babel npm install --save-dev babel-preset-es2015 var gulp = require(&quo ...

  4. maven创建springboot项目

    1.new Project 2.选择spring Initializr 3.选择next,可以自定义group.artifact,type里可以选择maven也可以选择gradle 4.选择sprin ...

  5. bzoj 1040 基向内环树dp

    #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk mak ...

  6. 【剑指offer】面试题 10. 斐波那契数列

    面试题 10. 斐波那契数列 题目一:求斐波那契数列的第n项 题目描述:求斐波拉契数列的第n项 写出一个函数,输入n,求斐波拉契(Fibonacci)数列的第n项.斐波拉契数列定义如下: C++ 实现 ...

  7. 【转载】TabLayout 源码解析

    原文地址:https://github.com/Aspsine/AndroidSdkSourceAnalysis/blob/master/article/TabLayout%E6%BA%90%E7%A ...

  8. 解决CDH的web界面使用nginx代理一些静态文件无法加载

    vim /opt/cm-/share/cmf/webapp/WEB-INF/spring/mvc-config.xml .... 注释此行 <bean class="com.cloud ...

  9. Linux基础系列-Day7

    NFS服务(基于CentOS 7.0) NFS(Network File System),网络文件系统,是linux与linux之间进行文件共享的服务,在NFS应用,本地NFS的客户端可以透明地读写位 ...

  10. 【BZOJ 4572】【SCOI 2016】围棋

    http://www.lydsy.com/JudgeOnline/problem.php?id=4572 轮廓线DP:设\(f(i,j,S,x,y)\). \(S\)表示\((i,1)\)到\((i, ...