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 ...
随机推荐
- 报文、http、https的理解
一.何为报文? 报文是网络中交换与传输的数据单位,即站点一次性要发送的数据块.报文包含了将要发送的完整的数据信息,其长短不一致,长度不限且可变. 二.报文的作用 报文多是多个系统之间需 ...
- maven项目启动报错;class path resource [com/ssm/mapping/] cannot be resolved to URL because it does not exist
项目启动报了一堆错误,其实都是class path resource [com/ssm/mapping/] cannot be resolved to URL because it does not ...
- 全球最大的3D数据集公开了!标记好的10800张全景图
Middlebury数据集 http://vision.middlebury.edu/stereo/data/ KITTI数据集简介与使用 https://blog.csdn.net/solomon1 ...
- DOS下读取PCI配置空间信息的汇编程序(通过IOCF8/IOCFC)
汇编程序编写的读取PCI配置空间信息的代码(通过IOCF8/IOCFC): ;------------------------------------------------ ;功能: 读取PCI 配 ...
- scrapy 自定义图片路径保存,并存到数据库中
scrapy中有个自带的pipeline工具,ImagesPipeline,可以专门用来储存图片到本地. 但默认储存地址无法配置,所以我们需要写一个自己的pipeline用于储存图片. 先分析一下我们 ...
- django实现类似触发器的效果
https://blog.csdn.net/pushiqiang/article/details/50652080?utm_source=blogxgwz1 https://blog.csdn.net ...
- java不常用但很有用的问题排查工具(持续完善)
因为用的频率不是很多,老忘掉,每次都要搜下,特记录下备忘. 查看进程的启动jvm选项 [root@iZ23nn1p4mjZ ~]# jinfo -flags 16603Attaching to pro ...
- Fedora 安装Docker
我使用的是yum安装, 下面提供我的yum源. name=Docker Repository baseurl=https://yum.dockerproject.org/repo/main/fedor ...
- svg动态添加小人
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&quo ...
- Windows 动态链接库DLL使用
转载:https://blog.csdn.net/heyabo/article/details/8721611 转载:https://www.cnblogs.com/jin521/p/5598529. ...