Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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 = [...new 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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

With Set you remove duplicates:

pendingPostFlushCbs = [1,2,5,5,6,8,8,]
const deduped = [...new Set(pendingPostFlushCbs)]
const deduped1 = [...pendingPostFlushCbs]
console.log(deduped)
console.log(deduped1)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading