2025年03月05日 建站教程
Set
是ES6
提供的一种新的数据结构,它跟数组一样用于存储有序的数据,下面web建站小编给大家讲解一下set()
的运用方法。
方法一:
let set = new Set() set.add(1) //Set(1) {1}
方法二:
let set = new Set([1,2,2,1,4,3,5]) console.log(set) //Set(5) {1, 2, 4, 3, 5}
方法三:
let arr = [1,2,2,1,4,3,5] Array.from(new Set(arr)) //(5) [1, 2, 4, 3, 5]
方法四:
let arr = [1,2,2,1,4,3,5] console.log([...new Set(arr)]) //(5) [1, 2, 4, 3, 5]
本文链接:http://so.lmcjl.com/news/24343/