当前位置:网站首页>(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']边栏推荐
- Android Security and Protection Policy
- leetcode每日一题:字符串压缩
- July 31, 2022 -- Take your first steps with C# -- Use C# to create readable code with conventions, spaces, and comments
- PDMan-domestic free general database modeling tool (minimalist, beautiful)
- ACL 2022 | 文本生成的相关前沿进展
- 小程序毕设作品之微信美食菜谱小程序毕业设计成品(3)后台功能
- slice、splice、split傻傻分不清
- redis6 跟着b站尚硅谷学习
- MFC implementation road map navigation system
- 【社区明星评选】第24期 8月更文计划 | 笔耕不辍,拒绝躺平!更多原创激励大礼包,还有华为WATCH FIT手表!
猜你喜欢

【likeshop】回收租凭系统100%开源无加密 商城+回收+租赁

xss-labs靶场挑战

What is a stepper motor?40 pictures to show you!

Drawing arrows of WPF screenshot control (5) "Imitation WeChat"

重庆市大力实施智能建造,推动建筑业数字化转型,助力“建造强市”

图解MySQL内连接、外连接、左连接、右连接、全连接......太多了

用户体验 | 如何度量用户体验 ?

石头科技打造硬核品牌力 持续出海拓展全球市场

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

小程序毕设作品之微信美食菜谱小程序毕业设计成品(3)后台功能
随机推荐
【钛晨报】国家统计局:7月制造业PMI为49%;玖富旗下理财产品涉嫌欺诈,涉及390亿元;国内航线机票燃油附加费8月5日0时起下调
Promise学习(二)一篇文章带你快速了解Promise中的常用API
用户体验 | 如何度量用户体验 ?
小程序毕设作品之微信美食菜谱小程序毕业设计成品(2)小程序功能
爱可可AI前沿推介(8.1)
机器学习 | MATLAB实现支持向量机回归RegressionSVM参数设定
【无标题】
xss-labs靶场挑战
这是我见过写得最烂的Controller层代码,没有之一!
【cartographer ros】十: 延时和误差分析
DBPack SQL Tracing 功能及数据加密功能详解
4种常见的鉴权方式及说明
C#/VB.NET convert PPT or PPTX to image
(ES6以上以及TS) Map对象转数组
MNIST是什么(plist是什么意思)
xss漏洞学习
Mini Program Graduation Works WeChat Food Recipes Mini Program Graduation Design Finished Products (4) Opening Report
Jenkins安装插件遇到的问题
Kaitian aPaaS mobile phone number empty number detection [Kaitian aPaaS battle]
R语言检验时间序列的平稳性:使用tseries包的adf.test函数实现增强的Dickey-Fuller(ADF)检验、检验时序数据是否具有均值回归特性(平稳性)、具有均值回归特性的案例