DEV Community

打coding的奥特曼
打coding的奥特曼

Posted on

去重

方法 1

const arr = [1,1,2,3,4,4,5]
const uniqueArr = [...new Set(arr)];
console.log(uniqueArr); //[ 1, 2, 3, 4, 5 ]
Enter fullscreen mode Exit fullscreen mode

方法2

import _ from 'lodash';
const arr = [1,1,2,3,4,4,5];
const uniqueArr = _.uniq(arr);
console.log(uniqueArr); //[ 1, 2, 3, 4, 5 ]
Enter fullscreen mode Exit fullscreen mode

Top comments (0)