当前位置:网站首页>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
边栏推荐
猜你喜欢
随机推荐
Mysql中的索引与视图
1-2 NodeJS的特点
.Net Core 下使用 Quartz —— 【7】作业和触发器之简单触发器
Multi cycle verification of El form
Leak detection and vacancy filling (II)
Unity3D对象池的理解与小例子
数据可视化进一步学习
浏览器中堆栈内存的底层处理
Promise(三)
Leak detection and vacancy filling (IX) -- Procedure
初步认识Promse
.Net Core 下使用 Quartz —— 【5】作业和触发器之触发器的通用属性和优先级
低代码开发平台整理
数据可视化百度地图进一步优化
el-table添加序号
JS手写兼容性事件绑定
JS实现私有属性
freeCodeCamp----time_calculator练习
SignalR实现从服务端主动发送数据到客户端
Color string conversion









