JavaScript Dictionary
2024-09-04 12:27:45
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();}
最新文章
- MySQL主从复制中常见的3个错误及填坑方案
- Java内存管理和垃圾回收
- 爬虫学习----获取cookie
- LOAD TABLE tbl_name FROM MASTER语法 SQL
- python中时间和时区
- log4j打印参数
- iOS 获取通讯录权限的时机
- 【HDOJ】1076 An Easy Task
- GDI+ 颜色表示
- android方向键被锁定的问题
- [译]Stairway to Integration Services Level 6 - SSIS 工作流管理基础
- C#又能出来装个B了。一步一步微信跳一跳自动外挂
- how tomcat works 读书笔记 八 载入器下
- 【.NET Core项目实战-统一认证平台】第十一章 授权篇-密码授权模式
- Mac 常用的快捷键
- Day 5内存管理,定义变量
- 如何定制 antd 的样式(theme)
- 【SSL】OV、DV和EV证书的区别
- vue router.push(),router.replace(),router.go()和router.replace后需要返回两次的问题
- (9) MySQL主主复制架构使用方法