JS字典 Dictionary类
字典 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();//
pbook.remove("Jennifer");
//pbook.clear();
pbook.showAll();//Mike -> 723; Jonathan -> 666;
pbook.count();//
JS字典 Dictionary类的更多相关文章
- C#创建安全的字典(Dictionary)存储结构
在上面介绍过栈(Stack)的存储结构,接下来介绍另一种存储结构字典(Dictionary). 字典(Dictionary)里面的每一个元素都是一个键值对(由二个元素组成:键和值) 键必须是唯一的,而 ...
- 索引器、哈希表Hashtabl、字典Dictionary(转)
一.索引器 索引器类似于属性,不同之处在于它们的get访问器采用参数.要声明类或结构上的索引器,使用this关键字. 示例: 索引器示例代码 /// <summary> /// 存储星 ...
- Python字典 (dictionary)
字典dict,是Python唯一的标准mapping类型,也是内置在Python解释器中的. mapping object把一个可哈希的值(hashable value)映射到一个任意的object上 ...
- Python字典(Dictionary)
Python中字典与类表类似,也是可变序列,不过与列表不同,他是无序的可变序列,保存的内容是以键 - 值对的形式存放的.类似我们的新华字典,他可以把拼音和汉字关联起来,通过音节表可以快速的找到想要的字 ...
- Java Dictionary 类存储键值
字典(Dictionary) 字典(Dictionary) 类是一个抽象类,它定义了键映射到值的数据结构. 当你想要通过特定的键而不是整数索引来访问数据的时候,这时候应该使用Dictionary. 当 ...
- 你真的了解字典(Dictionary)吗? C# Memory Cache 踩坑记录 .net 泛型 结构化CSS设计思维 WinForm POST上传与后台接收 高效实用的.NET开源项目 .net 笔试面试总结(3) .net 笔试面试总结(2) 依赖注入 C# RSA 加密 C#与Java AES 加密解密
你真的了解字典(Dictionary)吗? 从一道亲身经历的面试题说起 半年前,我参加我现在所在公司的面试,面试官给了一道题,说有一个Y形的链表,知道起始节点,找出交叉节点.为了便于描述,我把上面 ...
- C#工具类之字典扩展类
using System; using System.Collections; using System.Collections.Generic; using System.Linq; using S ...
- 对复杂字典Dictionary<T1,T2>排序问题
原文:对复杂字典Dictionary<T1,T2>排序问题 //VoltageCount类(电压值对应的数量): public class VoltageCount { ...
- javascript实现集合Set、字典Dictionary、HashTable
集合是由一组无序且唯一(即不能重复)的项组成的.这个数据结构使用了与有限集合相同的数学概念,但应用在计算机科学的数据结构中. function Set() { this.items = {}; } S ...
随机推荐
- UVA 11584 Partitioning by Palindromes (字符串区间dp)
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- ansible中常用模块详解
ansible中常用的模块详解: file模块 ansible内置的可以查看模块用法的命令如下: [root@docker5 ~]# ansible-doc -s file - name: Sets ...
- Spring Boot(九):定时任务
Spring Boot(九):定时任务 一.pom包配置 pom包里面只需要引入springboot starter包即可 <dependencies> <dependency> ...
- windows下openssl编译
昨晚,在编译rabbitmq-c时,使用cmake生成vs项目文件时遇到下列错误: CMake Error at C:/Program Files/CMake/share/cmake-3.6/Modu ...
- Java线程池详解,看这篇就够了!
构造一个线程池为什么需要几个参数?如果避免线程池出现OOM?Runnable和Callable的区别是什么?本文将对这些问题一一解答,同时还将给出使用线程池的常见场景和代码片段. 基础知识 Execu ...
- 20155201 网络攻防技术 实验五 MSF基础应用
20155201 网络攻防技术 实验五 MSF基础应用 一.实践内容 一个主动攻击实践,如ms08_067 一个针对浏览器的攻击,如ms11_050 一个针对客户端的攻击,如Adobe 成功应用任何一 ...
- xlrd与xlwt的下载
读excel表格: xlrd 地址:https://pypi.org/project/xlrd/ 下载语句:pip install xlrd 写excel表格: xlwt https://pypi.o ...
- topcoder srm 699 div1 -3
1.两个长度为$n$的数组$a,b$,$0 \leq a_{i} <2^{30}$.$b_{i}=-1$或者$b_{i}$为除$a_{i}$外其他数字的抑或值.现在给定$b$,如果不存在$a$, ...
- cf水题
题意:输入多组数据,有的数据代表硬币的长宽,有的数据代表钱包的长宽,问你当这组数据代表钱包的长宽时,能不能把它前面出现的所有硬币全部装下. 思路:只要钱包的长宽大于前面出现的所有硬币的长宽就可以装下, ...
- Oracle错误——ORA-01691: Lob 段SFZXP.SYS_LOB0000030381C00004$$无法通过8192(在表空间USERS中)扩展
问题 Oracle报错:ORA-01691: Lob 段SFZXP.SYS_LOB0000030381C00004$$无法通过8192(在表空间USERS中)扩展 问题原因 Oracle数据表空间不足 ...