博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
JS字典 Dictionary类
阅读量:7115 次
发布时间:2019-06-28

本文共 1213 字,大约阅读时间需要 4 分钟。

字典 Dictionary类
/*字典 Dictionary类*/function Dictionary() {    this.add = add;    this.datastore = new Array();    this.find = find;    this.remove = remove;    this.showAll = showAll;    this.count = count;    this.clear = clear;}function add(key, value) {    this.datastore[key] = value;}function find(key) {    return this.datastore[key];}function remove(key) {    delete this.datastore[key];}function showAll() {    var str = "";    for(var key in this.datastore) {        str += key + " -> " + this.datastore[key] + ";  "    }    console.log(str);}function count() {    /*var ss = Object.keys(this.datastore).length;    console.log("ssss   "+ss);    return Object.keys(this.datastore).length;*/    /**/    var n = 0;    for(var key in Object.keys(this.datastore)) {        ++n;    }    console.log(n);    return n;}function clear() {    for(var key in this.datastore) {        delete this.datastore[key];    }}var pbook = new Dictionary();pbook.add("Mike", "723");pbook.add("Jennifer", "987");pbook.add("Jonathan", "666");pbook.showAll();//Mike -> 723;  Jennifer -> 987;  Jonathan -> 666;pbook.count();//3pbook.remove("Jennifer");//pbook.clear();pbook.showAll();//Mike -> 723;  Jonathan -> 666;pbook.count();//2

 

转载地址:http://bvghl.baihongyu.com/

你可能感兴趣的文章
深入理解asp.net里的HttpModule机制
查看>>
java基础学习_常用类03_StringBuffer类、数组高级和Arrays类、Integer类和Character类_day13总结...
查看>>
Asp.net MVC Session过期异常的处理
查看>>
python ThreadPoolExecutor线程池使用
查看>>
IPTABLES 规则(Rules)
查看>>
关于URL编码
查看>>
深度学习的可解释性研究(一):让模型「说人话」
查看>>
QT5提示can not find -lGL的解决方法
查看>>
Silverlight/Windows8/WPF/WP7/HTML5周学习导读(9月17日-9月23日)
查看>>
Tap-Ahead:让移动搜索更加便捷的解决之道
查看>>
Windows Server2016 Hyper-v Cluster部署
查看>>
juniper路由器配置
查看>>
jQuery一点一滴系列教程(第三点)
查看>>
ARP解决方法/工具 真假ARP防范区别方法 ARP终极解决方案
查看>>
系统数据权限的实现方案
查看>>
华为vlan划分,单臂路由以及静态路由
查看>>
UCD 2010百度工作坊
查看>>
ssh2免密码登录
查看>>
4_move_find_into_model
查看>>
MySQL · 捉虫动态 · UK 包含 NULL 值备库延迟分析
查看>>