当前位置:网站首页>Difference between map and object
Difference between map and object
2022-06-24 20:29:00 【Gentle breeze - grass】
Map Follow object The difference between
| Map | Object | |
|---|---|---|
| Unexpected key value | Map By default, there are no keys | Object There's a prototype , The key name on the prototype chain may conflict with the setting key name of your own object |
| Type of key | Map The bond of can be any value , Include functions , Object or any basic type | Object Must be String perhaps Symbol |
| The order of the keys | Map Of Key Is ordered . So in iterations Map In the order in which the objects are inserted | Object Is chaotic |
| Size | Map The key value logarithm of can be easily passed through Size Property acquisition | Object The number of key value pairs of can only be calculated manually |
| iteration | Map yes iterable Of , So it can be iterated directly | iteration Object You need to get its key in some way before you can iterate |
| performance | It performs better in the scenario of frequent addition and deletion of key value pairs | In the scenario of frequent addition and deletion of key value pairs, no optimization is made |

Map The data structure has the following operation methods :
- size: map.size return Map The total number of members of the structure .
- set(key,value): Set the key name key Corresponding key value value, Then go back to the whole Map structure , If key There has been a value , Then the key value will be updated , Otherwise, the new key will be generated .( Because it returns the current Map object , So you can chain call )
- get(key): This method reads key Corresponding key value , If you can't find it key, return undefined.
- has(key): This method returns a Boolean value , Indicates whether a key is currently Map In the object .
- delete(key): This method deletes a key , return true, If the deletion fails , return false.
- clear():map.clear() Clear all members , no return value .
Map Structure native provides three ergodic generator functions and one ergodic method
- keys(): Returns the traverser of the key name .
- values(): The traverser that returns the key value .
- entries(): Returns the traverser of all members .
- forEach(): Traverse Map All members of .
边栏推荐
- Vxlan and MPLS: from data center to Metro Ethernet
- When querying the database with Gorm, reflect: reflect flag. mustBeAssignable using unaddressable value
- You can capture fingerprints with a mobile camera?! Accuracy comparable to signature and monogram, expert: you are aggravating discrimination
- 【建议收藏】时间序列预测应用、paper汇总
- Basic operation of sequence table
- 首个大众可用PyTorch版AlphaFold2复现,哥大开源OpenFold,star量破千
- Showcase是什么?Showcase需要注意什么?
- Some ideas about chaos Engineering
- 二叉树的基本性质与遍历
- 基于QT+MySQL的相机租赁管理系统
猜你喜欢

Nodered has no return value after successfully inserting into the database (the request cannot be ended)

Openstack actual installation and deployment tutorial, openstack installation tutorial

Bytebase 加入阿裏雲 PolarDB 開源數據庫社區

Bytebase joins Alibaba cloud polardb open source database community

Five day summary of software testing

宅男救不了元宇宙

Dongyuhui is not enough to bring goods to "rescue" live broadcast

物联网?快来看 Arduino 上云啦

网络安全审查办公室对知网启动网络安全审查,称其“掌握大量重要数据及敏感信息”

Implement the redis simple client customized based on socket
随机推荐
C language to realize mine sweeping (simple version)
Huawei cloud modelarts has ranked first in China's machine learning public cloud service market for the fourth time!
Predicate
Get to know the data structure of redis - hash
Apple doesn't need money, but it has no confidence in its content
得物多活架构设计之路由服务设计
[go Language brossage] go from 0 to Getting started 4: Advanced use of slice, Primary Review and Map Getting started Learning
Openvino2022 dev tools installation and use
《梦华录》“超点”,鹅被骂冤吗?
情绪识别AI竟「心怀鬼胎」,微软决定封杀它!
Bytebase 加入阿里云 PolarDB 开源数据库社区
C语言实现扫雷(简易版)
Teach you how to cancel computer hibernation
Maps are grouped according to the values of the passed in parameters (similar to database groupby)
gateway
"Ningwang" was sold and bought at the same time, and Hillhouse capital has cashed in billions by "selling high and absorbing low"
Uninstall tool v3.5.10.5670 single file portable official version
Comparative analysis of arrayblockingqueue and linkedblockingqueue
16个优秀业务流程管理工具
Basic operation of sequence table