在js中,集合去重可以选择用ES6新增加的Set集合来做。
示例如下:
const s = new Set();
[2, 3, 5, 4, 5, 2, 2].forEach(x => s.add(x));
for (let i of s) {
console.log(i);
}
输出结果为:
2
3
5
4
在js中,集合去重可以选择用ES6新增加的Set集合来做。
示例如下:
const s = new Set();
[2, 3, 5, 4, 5, 2, 2].forEach(x => s.add(x));
for (let i of s) {
console.log(i);
}
输出结果为:
2
3
5
4