UNPKG
gaga-js-utils
Version:
latest (1.0.0)
1.0.0
js tools
gaga-js-utils
/
src
/
array
/
unique
/
index.js
16 lines
(15 loc)
•
345 B
JavaScript
View Raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//数组去重
function
unique
(
arr
) {
let
appeard=
new
Set
()
return
arr.
filter
(
item
=>
{
//创建一个可以唯一标识对象的字符串id
let
id = item+
JSON
.
stringify
(item)
if
(appeard.
has
(id)) {
return
false
}
else
{ appeard.
add
(id)
return
true
} }) }
exports
.
unique
= unique;