当前位置:网站首页>The use of Ts - Map type
The use of Ts - Map type
2022-08-01 11:03:00 【little snail game】
Map related functions and properties:
- map.clear() – removes all key/value pairs from a Map object.
- map.set() – Set the key-value pair and return the Map object.
- map.get() – returns the value corresponding to the key, or undefined if it does not exist.
- map.has() – Returns a boolean value that determines whether the Map contains the value corresponding to the key.
- map.delete() – deletes an element in the Map, returns true if the deletion is successful, and returns false if it fails.
- map.size – Returns the number of key/value pairs in the Map object.
- map.keys() - Returns an Iterator object containing the keys of each element in the Map object.
- map.values() – Returns a new Iterator object containing the values of each element in the Map object.
Iteration Map
The elements in the Map object are inserted in order, and we can iterate over the Map object, each iteration returning the [key, value] array.
TypeScript uses for...of to iterate:
// iteration in map
let keys:Iterable
// iterate over all keys in map
for(let key of map.keys()) {
console.log("keys",key);
}
// iterate over all values in map
for(let value of map.values()){
console.log("values",value);
}
// iterate map
for(let entry of map.entries()){
console.log("entries1",entry[0], entry[1]);
}
for(let [key,value] of map.entries()) {
console.log("entries2",key, value);
map.forEach((value:number,key:string,map:Map
console.log("forEach",key,value);
p>
边栏推荐
- 【无标题】
- pgAdmin 4 v6.12 发布,PostgreSQL 开源图形化管理工具
- 轮询和长轮询的区别
- JS数据类型转换完全攻略
- 4种常见的鉴权方式及说明
- 基于ModelArts的物体检测YOLOv3实践【玩转华为云】
- Drawing arrows of WPF screenshot control (5) "Imitation WeChat"
- CTFshow,命令执行:web34、35、36
- July 31, 2022 -- Take your first steps with C# -- Use arrays and foreach statements in C# to store and iterate through sequences of data
- JWT
猜你喜欢
Promise learning (4) The ultimate solution for asynchronous programming async + await: write asynchronous code in a synchronous way
解决vscode输入! 无法快捷生成骨架(新版vscode快速生成骨架的三种方法)
EasyRecovery热门免费数据检测修复软件
Promise to learn several key questions (3) the Promise - state change, execution sequence and mechanism, multitasking series, abnormal penetration, interrupt the chain of Promise
STM32 Personal Notes - Watchdog
轮询和长轮询的区别
Online - GCeasy GC log analysis tools
图解MySQL内连接、外连接、左连接、右连接、全连接......太多了
OpenHarmony高校技术俱乐部计划发布
Solve vscode input! Unable to quickly generate skeletons (three methods for the new version of vscode to quickly generate skeletons)
随机推荐
回归预测 | MATLAB实现TPA-LSTM(时间注意力注意力机制长短期记忆神经网络)多输入单输出
STM32 Personal Notes - Embedded C Language Optimization
MySQL常用语句总结
pve 删除虚拟机「建议收藏」
CTFshow,命令执行:web33
华硕和微星多款产品将升级英特尔Arc A380和A310显卡
开天aPaaS之移动手机号码空号检测【开天aPaaS大作战】
Google Earth Engine——给影像添加一个属性对于单景的时间序列并返回影像
gc的意义和触发条件
各位大拿,安装Solaris 11.4操作系统,在安装数据库依赖包的时候包这个错,目前无原厂支持,也无安装盘,联网下载后报这个错,请教怎么解决?
跨域网络资源文件下载
退役划水
【cartographer ros】十: 延时和误差分析
进制与转换、关键字
2022年7月31日--使用C#迈出第一步--使用C#中的数组和foreach语句来存储和循环访问数据序列
C#/VB.NET 将PPT或PPTX转换为图像
语音聊天app源码——语音聊天派对
STM32入门开发 介绍IIC总线、读写AT24C02(EEPROM)(采用模拟时序)
JWT
Why Metropolis–Hastings Works