We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[19,"Tom", 1.65]
{"age": 19, "name": "Tom", "height": 165}
key
value
Dictonary
dict
HashMap
TreeMap
set(key,value)
remove(key)
has(key)
true
false
get(key)
clear()
size()
length
keys()
values()
// 字典结构的封装 export default class Map { constructor() { this.items = {}; } // has(key) 判断字典中是否存在某个key has(key) { return this.items.hasOwnProperty(key); } // set(key, value) 在字典中添加键值对 set(key, value) { this.items[key] = value; } // remove(key) 在字典中删除指定的key remove(key) { // 如果集合不存在该 key,返回false if (!this.has(key)) return false; delete this.items[key] } // get(key) 获取指定key的value,如果没有,返回undefined get(key) { return this.has(key) ? this.items[key] : undefined; } // 获取所有的key keys() { return Object.keys(this.items); } // 获取所有的value values() { return Object.values(this.items); } // size() 获取字典中的键值个数 size() { return this.keys().length; } // clear() 清空字典中所有的键值对 clear() { this.items = {} } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
字典
字典特点
[19,"Tom", 1.65]
,可通过下标值取出信息。{"age": 19, "name": "Tom", "height": 165}
,可以通过key
取出value
。字典和映射的关系
Dictonary
,Python 中的dict
。HashMap
和TreeMap
等。字典常见的操作
set(key,value)
向字典中添加新元素。remove(key)
通过使用键值来从字典中移除键值对应的数据值。has(key)
如果某个键值存在于这个字典中,则返回true
,反之则返回false
。get(key)
通过键值查找特定的数值并返回。clear()
将这个字典中的所有元素全部删除。size()
返回字典所包含元素的数量。与数组的length
属性类似。keys()
将字典所包含的所有键名以数组形式返回。values()
将字典所包含的所有数值以数组形式返回。字典封装
代码实现
The text was updated successfully, but these errors were encountered: