当前位置:网站首页>【Map 集合】
【Map 集合】
2022-07-27 17:48:00 【小气鬼SYQ】
new 一个实例化Map集合:
let m = new Map();1、map的属性:size
返回map的元素个数
2、map的方法:
<script>
// new 一个实例化Map 集合
let m = new Map();
// set-设置健和值,返回添加后的map(给已存在的键赋值后会覆盖掉之前的值
m.set("name", "张三");
m.set(5, "王老五")
m.set("5", "钻石王老五")
m.set("", "111")
console.log(m);
// get-获取某个key的值,返回key对应的值,没有则返回undefined
console.log(m.get(5));
// has-检测是否存在某个key,返回布尔值
console.log(m.has(6));
// delete-删除某个key及其对应的value,返回布尔值,成功删除则为true
console.log(m.delete(5));
console.log(m);
// clear返回undefind,原数组被清空
console.log(m.clear());
</script>3、遍历方式:
for of 只能遍历数组,遍历的是map的迭代器;for in 只能遍历的是对象;
// 使用for of 可以用来循环map迭代器
for (var key of m.keys()) {
console.log(key); //返回健
}
for (var v of m.values()) {
console.log(v); //返回值
}
for (var e of m.entries()) {
console.log(e); //返回数组,数组的第一项是健,第二项是值
}
// for of 只可以遍历数组,并遍历所有的元素, for in只可以遍历对象
var arr = [{ name: "张三", age: 30 }, { name: "张三", age: 30 }]
for (var item of arr) {
console.log(item);
}边栏推荐
- Program design Comprehensive Experiment III
- C171: attendance system
- Konka sold out its first 100000 storage master chips, with an estimated sales volume of 100million in 2020
- 获得微店商品详情 API
- Rodin installs the SMT solvers plug-in
- 汇顶科技:收购恩智浦VAS业务已完成交割
- JS 数组方法 forEach 和 map 比较
- 联发科发布中端游戏手机芯片Helio G80
- Talk about how redis handles requests
- uva1377
猜你喜欢

Ms721 load test

Ten year test old bird talk about mobile terminal compatibility test

使用cpolar建立一个商业网站(5)

Compiling ncnn with vs

New library online | cnopendata detailed address data of all patents in China

办公自动化解决方案——DocuWare Cloud 将应用程序和流程迁移到云端的完整的解决方案
![[paper reading] rich feature hierarchies for accurate object detection and semantic segmentation](/img/a9/690f52b5c4afba684f0add2434888c.png)
[paper reading] rich feature hierarchies for accurate object detection and semantic segmentation

What does bus mean

想转行软件测试,先过这三关,包含一份3000字超全测试学习指南

Unified Modeling Language (UML) specification
随机推荐
传英特尔将停掉台积电16nm代工的Nervana芯片
预处理与宏定义
总线Bus是什么意思
An in-depth understanding of crystal oscillation circuit derived from xtalin pin and xtalout pin of single chip microcomputer
‘vite‘ 不是内部或外部命令,也不是可运行的程序 或批处理文件
第2章 入门
内置函数锁相关
华为全联接大会2022开启曼谷之旅;Facebook推视频收入分成功能,创作者可获20%分成…
Product Manager: check where there is an error prompt of "system exception" on the offline
联发科发布中端游戏手机芯片Helio G80
最新获得淘宝app商品详情原数据 的API
Connection pool - return connection details (Part 1)
LG集团宣布将向湖北捐赠300万元现金、120万个口罩、1万套防护服
How to quickly improve the three minute response rate of Tiktok store? What will affect the reply rate of Tiktok store?
一看就懂的ESLint
LED high precision scale scheme specification
[C # network application programming] Experiment 3: process management exercise
22年PMP考试【全真敏捷试题】
连接池-归还连接详解(上)
电容串联与并联以及电容串联与平衡电阻