当前位置:网站首页>Map跟object 的区别
Map跟object 的区别
2022-06-24 19:02:00 【清风徐来-小草】
Map跟object 的区别
Map | Object | |
---|---|---|
意外的键值 | Map默认情况不包含任何键 | Object有一个原型,原型链上的键名有可能和自己对象的设置键名冲突 |
键的类型 | Map 的键可以是任意值,包含函数,对象或任意基本类型 | Object必须是String或者Symbol |
键的顺序 | Map的Key是有序的。因此在迭代的时候Map对象以插入的顺序返回键值 | Object 是无序的 |
Size | Map的键值对数可以轻易通过Size属性获取 | Object的键值对个数只能通过手动计算 |
迭代 | Map是 iterable 的,所以可以直接被迭代 | 迭代Object需要以某种方式获取它的键然后才能迭代 |
性能 | 在频繁的增删键值对的场景下表现更好 | 在频繁添加和删除键值对的场景下未作出优化 |
Map数据结构有以下操作方法:
- size: map.size 返回Map结构的成员总数。
- set(key,value):设置键名key对应的键值value,然后返回整个Map结构,如果key已经有值,则键值会被更新,否则就新生成该键。(因为返回的是当前Map对象,所以可以链式调用)
- get(key):该方法读取key对应的键值,如果找不到key,返回undefined。
- has(key):该方法返回一个布尔值,表示某个键是否在当前Map对象中。
- delete(key):该方法删除某个键,返回true,如果删除失败,返回false。
- clear():map.clear()清除所有成员,没有返回值。
Map结构原生提供是三个遍历器生成函数和一个遍历方法
- keys():返回键名的遍历器。
- values():返回键值的遍历器。
- entries():返回所有成员的遍历器。
- forEach():遍历Map的所有成员。
边栏推荐
- Coinbase将推出首个针对个人投资者的加密衍生产品
- Anti epidemic through science and technology: white paper on network insight and practice of operators | cloud sharing library No.20 recommendation
- Fundamentals of performance testing -- definitions of common terms
- Accurate calculation of task progress bar of lol mobile game
- 用自身细胞作为原料,首例3D打印耳朵移植成功!未来可打印更复杂器官
- Where are Xiaomi mobile phone's favorite SMS and how to delete them
- Apache+php+mysql environment construction is super detailed!!!
- lol手游之任务进度条精准计算
- R for Data Science (notes) -- data transformation (used by filter)
- 开放可编程基础设施(OPI)项目,重新定义DPU/IPU
猜你喜欢
Programmers spend most of their time not writing code, but...
Audio and video 2020 2021 2022 basic operation and parameter setting graphic tutorial
【Go语言刷题篇】Go从0到入门4:切片的高级用法、初级复习与Map入门学习
R for Data Science (note) -- data transformation (select basic use)
Methods for comparing float types in the kernel
苹果不差钱,但做内容“没底气”
苹果、微软、谷歌不再掐架,今年要合力干一件大事
Docker installing Oracle
Teach you how to cancel computer hibernation
Vs2017 add header file path method
随机推荐
[video tutorial] functions that need to be turned off in win10 system. How to turn off the privacy option in win10 computer
Behind Tiantian Jianbao storm: tens of millions in arrears, APP shutdown, and the founder's premeditated plan to run away?
Stop using system Currenttimemillis() takes too long to count. It's too low. Stopwatch is easy to use!
Eureka source code shallow reading - automatic fault removal
数字孪生行业案例:智慧港口数字化
Mq-2 smoke concentration sensor (STM32F103)
苹果不差钱,但做内容“没底气”
Win7 10 tips for installing Office2010 five solutions for installing MSXML components
Five day summary of software testing
两位湖南老乡,联手干出一个百亿IPO
Some ideas about chaos Engineering
Drawing DEM with GEE gracefully
Methods for comparing float types in the kernel
【Go语言刷题篇】Go从0到入门4:切片的高级用法、初级复习与Map入门学习
Power efficiency test
华为云ModelArts第四次蝉联中国机器学习公有云服务市场第一!
Test drive citus 11.0 beta (official blog)
Obstacle avoidance sensor module (stm32f103c8t6)
Kubernetes cluster deployment
Teach you how to view the number of connected people on WiFi in detail how to view the number of connected people on WiFi