字典 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类的更多相关文章

  1. C#创建安全的字典(Dictionary)存储结构

    在上面介绍过栈(Stack)的存储结构,接下来介绍另一种存储结构字典(Dictionary). 字典(Dictionary)里面的每一个元素都是一个键值对(由二个元素组成:键和值) 键必须是唯一的,而 ...

  2. 索引器、哈希表Hashtabl、字典Dictionary(转)

    一.索引器 索引器类似于属性,不同之处在于它们的get访问器采用参数.要声明类或结构上的索引器,使用this关键字. 示例:   索引器示例代码 /// <summary> /// 存储星 ...

  3. Python字典 (dictionary)

    字典dict,是Python唯一的标准mapping类型,也是内置在Python解释器中的. mapping object把一个可哈希的值(hashable value)映射到一个任意的object上 ...

  4. Python字典(Dictionary)

    Python中字典与类表类似,也是可变序列,不过与列表不同,他是无序的可变序列,保存的内容是以键 - 值对的形式存放的.类似我们的新华字典,他可以把拼音和汉字关联起来,通过音节表可以快速的找到想要的字 ...

  5. Java Dictionary 类存储键值

    字典(Dictionary) 字典(Dictionary) 类是一个抽象类,它定义了键映射到值的数据结构. 当你想要通过特定的键而不是整数索引来访问数据的时候,这时候应该使用Dictionary. 当 ...

  6. 你真的了解字典(Dictionary)吗? C# Memory Cache 踩坑记录 .net 泛型 结构化CSS设计思维 WinForm POST上传与后台接收 高效实用的.NET开源项目 .net 笔试面试总结(3) .net 笔试面试总结(2) 依赖注入 C# RSA 加密 C#与Java AES 加密解密

    你真的了解字典(Dictionary)吗?   从一道亲身经历的面试题说起 半年前,我参加我现在所在公司的面试,面试官给了一道题,说有一个Y形的链表,知道起始节点,找出交叉节点.为了便于描述,我把上面 ...

  7. C#工具类之字典扩展类

    using System; using System.Collections; using System.Collections.Generic; using System.Linq; using S ...

  8. 对复杂字典Dictionary<T1,T2>排序问题

    原文:对复杂字典Dictionary<T1,T2>排序问题 //VoltageCount类(电压值对应的数量):    public class VoltageCount    {     ...

  9. javascript实现集合Set、字典Dictionary、HashTable

    集合是由一组无序且唯一(即不能重复)的项组成的.这个数据结构使用了与有限集合相同的数学概念,但应用在计算机科学的数据结构中. function Set() { this.items = {}; } S ...

随机推荐

  1. POJ 3624 Charm Bracelet (01背包)

    题目链接:http://poj.org/problem?id=3624 Bessie has gone to the mall's jewelry store and spies a charm br ...

  2. JXNU暑期选拔赛

    最小的数 Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 65535/32768K (Java/Other) Total Submissi ...

  3. python sqlite3 数据库操作

    python sqlite3 数据库操作 SQLite3是python的内置模块,是一款非常小巧的嵌入式开源数据库软件. 1. 导入Python SQLite数据库模块 import sqlite3 ...

  4. 分页的模块layui

    //调用分页模块 var laypage = layui.laypage; //分页的配置项 laypage.render({ elem:"page",//(指向存放分页的容器,值 ...

  5. kivy 滑动

    from kivy.uix.gridlayout import GridLayout from kivy.app import App from kivy.lang.builder import Bu ...

  6. 【题解】Luogu CF915E Physical Education Lessons

    原题传送门:CF915E Physical Education Lessons 前置芝士:珂朵莉树 窝博客里对珂朵莉树的介绍 没什么好说的自己看看吧 这道题很简单啊 每个操作就是区间赋值,顺带把总和修 ...

  7. Linux pip 命令无法使用问题

    Linux pip 命令无法使用问题 pip 命令无法使用,说明 pip 没有安装,我们可以使用终端命令进行安装. sudo apt-get installl python-pip 安装成功之后,可以 ...

  8. 鸡兔同笼问题(Java)

    问题描述:编程解决鸡兔同笼问题,笼子中鸡兔共有35只,94只脚,求有鸡和兔各有几只 我的代码: /** * 鸡兔同笼问题 * @author Administrator * */ public cla ...

  9. 02: git分支管理

    目录:GIT其他篇 01: git & github 02: git分支管理 目录: 1.1 Git常用命令 1.2 主要分支(保护分支) 1.3 特性分支:feature (开发分支合并到d ...

  10. Linux限制普通用户只能使用某命令

    修改sudoers(/etc/sudoers)