当前位置:网站首页>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 开源图形化管理工具
- Google Earth Engine——给影像添加一个属性对于单景的时间序列并返回影像
- Endorsed in 2022 years inventory | product base, science and technology, guangzhou automobile group striding forward
- DBPack SQL Tracing 功能及数据加密功能详解
- 机器学习 | MATLAB实现支持向量机回归RegressionSVM参数设定
- Android 安全与防护策略
- Generate certificates using KeyStore
- MFC implementation road map navigation system
- 浏览器快捷键大全
- Google Earth Engine APP——15行代码搞定一个inspector高程监测APP
猜你喜欢
复现assert和eval成功连接或失败连接蚁剑的原因
DBPack SQL Tracing 功能及数据加密功能详解
新书上市 |《谁在掷骰子?》在“不确定性时代”中确定前行
Mini Program Graduation Works WeChat Food Recipes Mini Program Graduation Design Finished Products (2) Mini Program Functions
如何在IntellJ IDEA中批量修改文件换行符
Promise learning (1) What is Promise?how to use?How to solve callback hell?
.NET深入解析LINQ框架(三:LINQ优雅的前奏)
Promise学习(二)一篇文章带你快速了解Promise中的常用API
Drawing arrows of WPF screenshot control (5) "Imitation WeChat"
redis6 跟着b站尚硅谷学习
随机推荐
新书上市 |《谁在掷骰子?》在“不确定性时代”中确定前行
Solve vscode input! Unable to quickly generate skeletons (three methods for the new version of vscode to quickly generate skeletons)
Kaitian aPaaS mobile phone number empty number detection [Kaitian aPaaS battle]
判断JS数据类型的四种方法
C#/VB.NET convert PPT or PPTX to image
跨域网络资源文件下载
轮询和长轮询的区别
Online - GCeasy GC log analysis tools
How I secured 70,000 ETH and won a 6 million bug bounty
shell--面试题
小程序毕设作品之微信美食菜谱小程序毕业设计成品(4)开题报告
小程序毕设作品之微信美食菜谱小程序毕业设计成品(1)开发概要
Mini Program Graduation Works WeChat Food Recipes Mini Program Graduation Design Finished Products (3) Background Functions
Promise学习(三)Promise的几个关键性问题 -- 状态改变、执行顺序与机制、多任务串联、异常穿透、中断promise链
Endorsed in 2022 years inventory | product base, science and technology, guangzhou automobile group striding forward
石头科技打造硬核品牌力 持续出海拓展全球市场
pve 删除虚拟机「建议收藏」
监视网络连接的ss命令
机器学习 | MATLAB实现支持向量机回归RegressionSVM参数设定
DBPack SQL Tracing 功能及数据加密功能详解