当前位置:网站首页>set--数据解构
set--数据解构
2022-07-27 17:48:00 【小气鬼SYQ】
<script>
// 去重
var s = new Set([1, 2, 3, 3, 4, 4, 5]);
// 转数组
// console.log(Array.from(s));
// size--获取set长度
console.log(s.size);
// add--添加值,返回set本身合集
console.log(s.add(6));
// delete--删除一个值,返回布尔值
console.log(s.delete(1)); //true
console.log(s); //原数组被改变
// has--查找某个值 返回布尔值
console.log(s.has(9)); // false
// clear--清除所有成员,没有返回值,改变原数组,被清空
console.log(s.clear()); //返回undifind
console.log(s); //所有值被清空
</script>set集合也可以使用for of 遍历,以及map方法
let s = new Set(["前端", "后端", "大数据"])
console.log(s.keys()); //返回的是set集合的内容
console.log(s.values()); //返回的是set集合的内容
console.log(s.entries()); //返回的是key和values,也都是内容
// 遍历 set合集
for (var v of s.keys()) {
console.log(v);
}
for (var v of s.values()) {
console.log(v);
}
for (var v of s.entries()) {
console.log(v);
}边栏推荐
- Chapter 3 basic operation
- Libpcap library and pcap_ Sendpacket interface function understanding
- [Redis] Redis穿透、雪崩和击穿
- 调整数组使奇数全部都位于偶数前
- New library online | cnopendata detailed address data of all patents in China
- 【PyTorch系列】PyTorch之torchvision 图像处理库详解
- 内置函数其它函数
- es6删除对象的属性_ES6删除对象中的某个元素「建议收藏」
- PMP practice once a day | don't get lost in the exam -7.27 (including agility + multiple choices)
- C # network application programming, experiment 1: WPF exercise
猜你喜欢

codeforces每日5题(均1500)-第二十四天

Common errors reported by pytorch

Unity2d dynamic cartoon script (animation demonstration II for the chapter of Tiger Bridge)

Software configuration | tigervnc download, installation and configuration

1.2 pedestrian recognition based on incremental generation of occlusion and confrontation suppression (code understanding and experimental progress + Report)

ViewUI 中 DatePicker 日期选择器在 IE11 浏览器中兼容解决方案

Chapter 3 basic operation

Unified Modeling Language (UML) specification

2022年,软件测试还能学吗?别学了,软件测试岗位饱和了...

Technology sharing | how to do Assertion Verification in interface automated testing?
随机推荐
Product Manager: check where there is an error prompt of "system exception" on the offline
PMP practice once a day | don't get lost in the exam -7.27 (including agility + multiple choices)
PKI/TLS 工具之CFSSL —— 筑梦之路
#yy关于鱼的英文学习
If you want to switch to software testing, you should pass these three tests first, including a 3000 word super full test learning guide
UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xff in position 0: invalid start byte
邬贺铨:因地制宜 数字化技术赋能“双碳”实践
Rodin installs the SMT solvers plug-in
Huawei connect conference 2022 opens Bangkok trip; Facebook pushes the video revenue sharing function, and the creator can get 20% share
【OpenBMC 系列】4.启动流程 使用qume模拟ast2600-evb
uva1421
LED high precision scale scheme specification
继华为、联发科之后,这家手机芯片厂商宣布向武汉捐款700万
MVCC的底层原理
JS array method foreach and map comparison
预处理与宏定义
ACL11.12
西数移动硬盘无法读取(高枕无忧的成语)
【PyTorch系列】PyTorch之torchvision 图像处理库详解
Acwing 692. g bus count difference + prefix and