当前位置:网站首页>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>
边栏推荐
猜你喜欢

冰冰学习笔记:gcc、gdb等工具的使用

基于ArkUI eTS开发的坚果食谱(NutRecipes)

redis6 跟着b站尚硅谷学习

.NET深入解析LINQ框架(三:LINQ优雅的前奏)

博弈论(Depu)与孙子兵法(42/100)

语音聊天app源码——语音聊天派对

C#/VB.NET convert PPT or PPTX to image

Android Security and Protection Policy

Dapr 与 NestJs ,实战编写一个 Pub & Sub 装饰器

Mini Program Graduation Works WeChat Food Recipes Mini Program Graduation Design Finished Products (4) Opening Report
随机推荐
如何设计一个分布式 ID 发号器?
DBPack SQL Tracing 功能及数据加密功能详解
LeakCanary如何监听Service、Root View销毁时机?
跨域网络资源文件下载
昇思大模型体验平台初体验——以小模型LeNet为例
shell--第九章练习
开天aPaaS之移动手机号码空号检测【开天aPaaS大作战】
万字解析:vector类
力扣解法汇总1374-生成每种字符都是奇数个的字符串
PDMan-domestic free general database modeling tool (minimalist, beautiful)
一篇文章,带你详细了解华为认证体系证书(2)
【cartographer ros】10: Delay and error analysis
CTFshow,命令执行:web37
Mini Program Graduation Works WeChat Food Recipes Mini Program Graduation Design Finished Products (3) Background Functions
Flutter Widget 如何启用和屏蔽点击事件
MFC implementation road map navigation system
石头科技打造硬核品牌力 持续出海拓展全球市场
回归预测 | MATLAB实现TPA-LSTM(时间注意力注意力机制长短期记忆神经网络)多输入单输出
Golang内存分析工具gctrace和pprof实战
RK3399平台开发系列讲解(内核入门篇)1.52、printk函数分析 - 其函数调用时候会关闭中断