Best shallow copy of array?

When I was reading the vue source code today, I encountered a writing method that I didn’t understand.
view source

const deduped = [ Set(pendingPostFlushCbs)]

In my opinion, it is a shallow copy of the array. But why should I convert to Set first,can I have better performance? How should I understand it?

>Solution :

With Set you remove duplicates:

pendingPostFlushCbs = [1,2,5,5,6,8,8,]
const deduped = [ Set(pendingPostFlushCbs)]
const deduped1 = [...pendingPostFlushCbs]

Leave a Reply