当前位置:网站首页>(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']边栏推荐
- 复现assert和eval成功连接或失败连接蚁剑的原因
- C#/VB.NET 将PPT或PPTX转换为图像
- 【likeshop】回收租凭系统100%开源无加密 商城+回收+租赁
- Promise learning (1) What is Promise?how to use?How to solve callback hell?
- leetcode/submatrix element sum
- 【无标题】
- SCHEMA解惑
- Istio Meetup China:全栈服务网格 - Aeraki 助你在 Istio 服务网格中管理任何七层流量
- 腾讯云原生:Areaki Mesh 在 2022 冬奥会视频直播应用中的服务网格实践
- 一文说明白ECDSA spec256k1 spec256r1 EdDSA ed25519千丝万缕的关系
猜你喜欢

【钛晨报】国家统计局:7月制造业PMI为49%;玖富旗下理财产品涉嫌欺诈,涉及390亿元;国内航线机票燃油附加费8月5日0时起下调

Promise learning (2) An article takes you to quickly understand the common APIs in Promise

Android 安全与防护策略

数字化转型实践:世界级2B数字化营销的方法框架

利用正则表达式的回溯实现绕过

Flutter Widget 如何启用和屏蔽点击事件

新一代超安全蜂窝电池, 思皓爱跑上市13.99万元起售

小程序毕设作品之微信美食菜谱小程序毕业设计成品(2)小程序功能

一篇文章,带你详细了解华为认证体系证书(1)

如何从完美的智能合约中窃取 1 亿美元
随机推荐
Mysql索引相关的知识复盘一
回归预测 | MATLAB实现TPA-LSTM(时间注意力注意力机制长短期记忆神经网络)多输入单输出
我是如何保护 70000 ETH 并赢得 600 万漏洞赏金的
RK3399 platform development series on introduction to (kernel) 1.52, printk function analysis - the function call will be closed
利用正则表达式的回溯实现绕过
【cartographer ros】10: Delay and error analysis
activiti工作流的分页查询避坑
Promise learning (4) The ultimate solution for asynchronous programming async + await: write asynchronous code in a synchronous way
如何获取微信视频号的地址(微信公众号的链接地址)
Mysql index related knowledge review one
Promise learning (1) What is Promise?how to use?How to solve callback hell?
How I secured 70,000 ETH and won a 6 million bug bounty
Drawing arrows of WPF screenshot control (5) "Imitation WeChat"
A new generation of ultra-safe cellular batteries, Sihao Airun goes on sale starting at 139,900 yuan
Why Metropolis–Hastings Works
【社区明星评选】第24期 8月更文计划 | 笔耕不辍,拒绝躺平!更多原创激励大礼包,还有华为WATCH FIT手表!
表达式引擎在转转平台的实践
OpenHarmony高校技术俱乐部计划发布
mysql进阶(二十二)MySQL错误之Incorrect string value中文字符输入错误问题分析
Hot review last week (7.25 7.31)