数组去重:

const arr = [1,2,3,3,5,6,2];
const arr1 = [...new Set(arr)]; // 方法一
const arr2 = Array.from(new Set(arr)); // 方法二
console.log(arr1); // [1, 2, 3, 5, 6]
console.log(arr2); // [1, 2, 3, 5, 6]

字符串去重:

const str = 'abbfha';
const str1 = [...new Set(str)].join('');  // 方法一
const str2 = Array.from(new Set(str)).join(''); // 方法二
console.log(str1); // abfh
console.log(str2); // abfh

相关文章:

  • 2021-09-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-01
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-05-18
  • 2022-12-23
  • 2022-01-01
  • 2021-09-13
相关资源
相似解决方案