当前位置:网站首页>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的所有成员。
边栏推荐
- Some small requirements for SQL Engine for domestic database manufacturers
- The name of the button in the Siyuan notes toolbar has changed to undefined. Has anyone ever encountered it?
- JMeter environment deployment
- Some ideas about chaos Engineering
- 字节、腾讯也下场,这门「月赚3000万」的生意有多香?
- IP address to integer
- Steering gear control (stm32f103c8t6)
- Accurate calculation of task progress bar of lol mobile game
- Write a positive integer to the node and return a floating-point number multiplied by 0.85 when reading the node
- [suggested collection] time series prediction application and paper summary
猜你喜欢

苹果不差钱,但做内容“没底气”

Teach you how to view the number of connected people on WiFi in detail how to view the number of connected people on WiFi

网络安全审查办公室对知网启动网络安全审查,称其“掌握大量重要数据及敏感信息”
![[video tutorial] functions that need to be turned off in win10 system. How to turn off the privacy option in win10 computer](/img/14/0313857adc178ecee4c866a05e54aa.jpg)
[video tutorial] functions that need to be turned off in win10 system. How to turn off the privacy option in win10 computer

Making startup U disk -- Chinese cabbage U disk startup disk making tool V5.1

Bytebase加入阿里云PolarDB开源数据库社区

Some small requirements for SQL Engine for domestic database manufacturers
The name of the button in the Siyuan notes toolbar has changed to undefined. Has anyone ever encountered it?

What are the functions of IBPs open source form designer?

To open the registry
随机推荐
天天鉴宝暴雷背后:拖欠数千万、APP停摆,创始人预谋跑路?
【建议收藏】时间序列预测应用、paper汇总
[suggested collection] time series prediction application and paper summary
First understand redis' data structure - string
[go Language brossage] go from 0 to Getting started 4: Advanced use of slice, Primary Review and Map Getting started Learning
Bytebase 加入阿里云 PolarDB 开源数据库社区
Microsoft Office Excel 2013 2016 graphic tutorial on how to enable macro function
Steering gear control (stm32f103c8t6)
Programmers spend most of their time not writing code, but...
Full link service tracking implementation scheme
Camera module and hardware interface of Camera1 camera
Vxlan and MPLS: from data center to Metro Ethernet
Information theory of popular science Shannon
Teach you how to view the number of connected people on WiFi in detail how to view the number of connected people on WiFi
Todesk remote control, detailed introduction and tutorial
Nodered has no return value after successfully inserting into the database (the request cannot be ended)
Q1: error in JMeter filename must not be null or empty
Geoscience remote sensing data collection online
What is showcase? What should showcase pay attention to?
Write a positive integer to the node and return a floating-point number multiplied by 0.85 when reading the node