JavaScript 数据类型之(Map和Set)
JavaScript个人整理
Map
var names = ["史迪奇","史迪仔","强霸"]; var scores = [100,100,36]
var map = naw Map([["史迪奇",100],["史迪仔",100],["强霸",36]]); var name = map.get("史迪奇"); map.set("独眼霹雳",60); map.delete("强霸");
|
Set
set.add(3) set.delete("强霸"); console.log(set.has(3))
|
iterator
遍历数组
var arr = [1,2,3] for (var x of arr){ console.log(x) }
|
遍历map
var map = new Map([["史迪奇",100],["史迪仔",100],["强霸",100]]); for (var x of map){ console.log(x) }
|
遍历set
var set = new set([["史迪奇",100],["史迪仔",100],["强霸",100]]); for (var x of set){ console.log(x) }
|
作者: 我叫史迪奇
本文来自于:
https://sdq3.link/JavaScript-Map-Set.html博客内容遵循 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0) 协议