当前位置:网站首页>Set and map
Set and map
2022-04-23 06:51:00 【KK should continue to work hard】
Set And Map
Set
Definition
A set of unordered and non repetitive data sets
Methods and properties
- ( One ) Method
- add(): to Set Set add data , Only one value can be added , It can be used continuously , Such as :add(1).add(2))
- has(): Judge Set Whether the collection has this value , There is a return true, No return false
- delete(): Delete Set Some data in the collection , You can only delete one value at a time . Delete nonexistent data , Nothing will happen , No errors reported
- clear(): Empty Set The data of
- forEach(): Traverse Set.s.forEach(function(value,key,set){},this Point to ),Set In the collection value and key Same value ,set This for traversal Set aggregate
- ( Two ) attribute
- size:Set The length of the set , It's equivalent to length
Set Arguments to the constructor
- Array
- character string
- arguments
- NodeList
- Set
// Copy a Set,s2 It's not equal to s1
const s1 = new Set([1,2,3]);
const s2 = new Set(s1);
Be careful :Set Judge whether the data is repeated according to === principle , but NaN Different ,Set Medium NaN be equal to NaN
Map
Definition
Set of key value pairs ,Map Any data type can be used as its key, Arrays can only be legal identifiers
Methods and properties
- ( One ) Method
- set(): Add a new key value pair , If the key already exists , The key value pair added after overwriting the existing
- get(): Get value by key
- has(): Judge Map Is there a key in the
- delete(): Delete a data , If you delete a key that does not exist , Nothing will happen and no error will be reported
- clear(): Delete all data
- forEach(): Traverse Map,m.forEach(function(value,key,map){},this Point to )
- ( Two ) attribute
- size:Map The length of , Similar to... In an array length
Map Arguments to the constructor
- Array ( It can only be a two-dimensional array )
const map = new Map([
['name': 'xxx'],
['age': 18]
])
- Set( In the form of a two-dimensional array )、Map
// Copy Map
const m1 = new Map([
['name': 'xxx'],
['age': 18]
])
const m2 = new Map(m1)
Be careful :Map Of NaN And Set equally , The same is true for key names
版权声明
本文为[KK should continue to work hard]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230551363702.html
边栏推荐
猜你喜欢
随机推荐
WebSocket(基础)
百度地图基础案例
leetcode刷题之整数加一
Node数据流
浏览器工作原理与实践
.Net Core 下使用 Quartz —— 【6】作业和触发器之触发器的日历
数据可视化百度地图进一步优化
1-5 NodeJS CommonJs规范
Promise(三)
.NET类型转移
js查找字符串中出现了三次的字符
算数表达式
柯里化实现函数连续调用计算累加和
Use of shell scripts & and 𞓜
手动实现call,apply,bind函数
【无标题】js中的类型判断
The use of volatile in C language
关于软件的空间占用,安装目录
ASP.NET CORE JWT认证
.NET Standard详解