Set ——最简单的数组去重

简介: Set ——最简单的数组去重

Set ——最简单的数组去重,一行代码就可以解决

let arr1 = [ 1, 2, 3, 3, 4, 4, 4, 5 ]
let arr2 = [ ...new Set(arr1) ]     // [ 1, 2, 3, 4, 5 ]

目录
相关文章
|
9月前
Set集合介绍
Set集合介绍
38 0
数组从排1,2,3,4,5,冒泡排序的写法 .sort,升序写法 arr.sort(function (a,b){return a - b})
数组从排1,2,3,4,5,冒泡排序的写法 .sort,升序写法 arr.sort(function (a,b){return a - b})
|
11月前
数组去重的第二种方式indexof
数组去重的第二种方式indexof
31 0
数组去重-set
ES6 提供了新的数据结构 Set 它类似于数组,但是成员的值都是唯一的,没有重复的值 (set本身是一个构造函数,用来生成 Set 数据结构)
|
2月前
|
C++
c++ set、map的四种自定义排序方法
c++ set、map的四种自定义排序方法
103 0
|
2月前
set集合
set集合
24 0
|
9月前
|
存储 Java
Set集合详解
Set集合详解
47 0
|
11月前
|
JavaScript 索引
JS数组常用方法(超级详细,含理解) push、pop、unshift、shift、splice、slice、concat、join、revres、indexOf、sort、filter、map
JS数组常用方法(超级详细,含理解) push、pop、unshift、shift、splice、slice、concat、join、revres、indexOf、sort、filter、map
195 0
|
11月前
Array.prototype.concat
Array.prototype.concat
41 0
sort() 方法是最强大的数组方法之一。
sort() 方法是最强大的数组方法之一。
61 0