javascript知识点查缺补漏

1,过滤唯一值

ES6中的set对象类型,配合展开操作...一起,可以使用它来创建新数组,使得该数组只有唯一的值。

eg.

const array = [1, 1, 2, 3, 5, 5, 1]
const uniqueArray = [...new Set(array)];
console.log(uniqueArray); // Result: [1, 2, 3, 5]

 此方法适用于包含基本类型的数组:undefinednullbooleanstringnumber。 (如果你有一个包含对象,函数或其他数组的数组,你需要一个不同的方法!)

后续更新

猜你喜欢

转载自www.cnblogs.com/tiramisu-lizi/p/10928872.html