当前位置:网站首页>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>
边栏推荐
- .NET深入解析LINQ框架(三:LINQ优雅的前奏)
- 如何解决 chrome 浏览器标签过多无法查看到标题的情况
- STM32 Personal Notes - Embedded C Language Optimization
- 如何从完美的智能合约中窃取 1 亿美元
- 千万级乘客排队系统重构&压测方案——总结篇
- 【cartographer ros】10: Delay and error analysis
- MFC实现交通图导航系统
- 分类预测 | MATLAB实现1-DCNN一维卷积神经网络分类预测
- Google Earth Engine——给影像添加一个属性对于单景的时间序列并返回影像
- Promise learning (1) What is Promise?how to use?How to solve callback hell?
猜你喜欢
轮询和长轮询的区别
C#/VB.NET convert PPT or PPTX to image
新书上市 |《谁在掷骰子?》在“不确定性时代”中确定前行
退役划水
各位大拿,安装Solaris 11.4操作系统,在安装数据库依赖包的时候包这个错,目前无原厂支持,也无安装盘,联网下载后报这个错,请教怎么解决?
Promise learning (4) The ultimate solution for asynchronous programming async + await: write asynchronous code in a synchronous way
Jenkins安装插件遇到的问题
Promise learning (2) An article takes you to quickly understand the common APIs in Promise
2022年中盘点 | 产品打底,科技背书,广汽集团阔步向前
Small application project works WeChat gourmet recipes applet graduation design of finished product (1) the development profile
随机推荐
Endorsed in 2022 years inventory | product base, science and technology, guangzhou automobile group striding forward
广域铭岛入选2022年重庆市数字经济产业发展试点示范项目名单
Promise learning (1) What is Promise?how to use?How to solve callback hell?
2022年7月31日--使用C#迈出第一步--使用 C# 创建具有约定、空格和注释的易读代码
The first experience of Shengsi large model experience platform——Take the small model LeNet as an example
Promise learning (4) The ultimate solution for asynchronous programming async + await: write asynchronous code in a synchronous way
Cross-domain network resource file download
图解MySQL内连接、外连接、左连接、右连接、全连接......太多了
Mysql索引相关的知识复盘一
昇思大模型体验平台初体验——以小模型LeNet为例
冰冰学习笔记:gcc、gdb等工具的使用
监视网络连接的ss命令
shell--第九章练习
Glassmorphism design style
Browser shortcut keys
Promise to learn several key questions (3) the Promise - state change, execution sequence and mechanism, multitasking series, abnormal penetration, interrupt the chain of Promise
Kaitian aPaaS mobile phone number empty number detection [Kaitian aPaaS battle]
小程序毕设作品之微信美食菜谱小程序毕业设计成品(3)后台功能
什么是步进电机?40张图带你了解!
How to Steal $100 Million from the Perfect Smart Contract