Set数据的特性就是无重复数据
- 数组去重①
[...new Set(arr)]
- 数组去重②
function dedupe(array) {
return Array.from(new Set(array));
}
dedupe([1, 1, 2, 3]) // [1, 2, 3]
- 去除字符串的重复字符
[...new Set('abcca')].join('')
Set数据的特性就是无重复数据
[...new Set(arr)]
function dedupe(array) {
return Array.from(new Set(array));
}
dedupe([1, 1, 2, 3]) // [1, 2, 3]
[...new Set('abcca')].join('')