当前位置:网站首页>(ES6 and above and TS) Map object to array
(ES6 and above and TS) Map object to array
2022-08-01 11:19:00 【little snail game】
const map = new Map();map.set('1', 'one');map.set('2'.'two');// Get the value array of the map objectArray.from(map).map(item => item[1]);// ['one', 'two']
Array.from returns a two-dimensional array after executing the map object. The elements of the array are the key-value arrays of the map, and the length is 2
Array.from(map); // [['1', 'one'], ['2', 'two']]
So if the same method can be used to obtain the key array of the map object in the following section
Array.from(map).map(item => item[0]); // ['1', '2']
Based on the values() function provided by the map object
values() returns a MapIterator object, you can call the values().next() method to get the value in turn, and you can only get it once at a time, this way you can directly get the value array of the map object
Array.from(map.values())// ['one', 'two']
The map object also provides the keys() method
The same code below can get the key array of the map object
Array.from(map.keys())// ['1', '2']
In addition, map objects also support the use of spread operators in arrays
More intuitive and concise expression
[...map.values()] // ['one', 'two']
边栏推荐
- jmeter
- C language implementation!20000 in 4 seconds
- 万字解析:vector类
- 如何从完美的智能合约中窃取 1 亿美元
- Browser shortcut keys
- DBPack SQL Tracing 功能及数据加密功能详解
- Aeraki Mesh 加入 CNCF 云原生全景图
- redis6 跟着b站尚硅谷学习
- Kaitian aPaaS mobile phone number empty number detection [Kaitian aPaaS battle]
- js中常用追加元素的几种方法:append,appendTo,after,before,insertAfter,insertBefore,appendChild
猜你喜欢
Online - GCeasy GC log analysis tools
Jenkins安装插件遇到的问题
大众碰到点评的一个字体反爬,落地技术也是绝了
The meaning and trigger conditions of gc
华硕和微星多款产品将升级英特尔Arc A380和A310显卡
Promise learning (1) What is Promise?how to use?How to solve callback hell?
小程序毕设作品之微信美食菜谱小程序毕业设计成品(4)开题报告
Mysql index related knowledge review one
Mini Program Graduation Works WeChat Food Recipes Mini Program Graduation Design Finished Products (4) Opening Report
回归预测 | MATLAB实现TPA-LSTM(时间注意力注意力机制长短期记忆神经网络)多输入单输出
随机推荐
Small application project works WeChat gourmet recipes applet graduation design of finished product (1) the development profile
xss漏洞学习
ACL 2022 | 文本生成的相关前沿进展
activiti工作流的分页查询避坑
The use of Ts - Map type
SCHEMA解惑
【cartographer ros】十: 延时和误差分析
回归预测 | MATLAB实现TPA-LSTM(时间注意力注意力机制长短期记忆神经网络)多输入单输出
表达式引擎在转转平台的实践
JS 中的 undefined 和 null 的区别
MNIST是什么(plist是什么意思)
R语言检验时间序列的平稳性:使用tseries包的adf.test函数实现增强的Dickey-Fuller(ADF)检验、检验时序数据是否具有均值回归特性(平稳性)、具有均值回归特性的案例
.NET analyzes the LINQ framework in depth (three: the elegant prelude of LINQ)
jmeter
如何获取微信视频号的地址(微信公众号的链接地址)
C#/VB.NET 将PPT或PPTX转换为图像
稀疏表示--学习笔记
Stone Technology builds hard-core brand power and continues to expand the global market
千万级乘客排队系统重构&压测方案——总结篇
The meaning and trigger conditions of gc