By default, a
Set is meant to store unique values and spreading it into an array is enough to give us the desired result.
const uniqueArray = (arr) => [...new Set(arr)] uniqueArray(['ReactJS', 'NextJS', 'NodeJS', 'ReactJS']) // ['ReactJS', 'NextJS', 'NodeJS'] uniqueArray([1, 2, 2, 3, 3, 3, 4, 4, 4, 4]) // [1, 2, 3, 4]
I hope that's helpful and interesting to you. 👋🏼
Did you know you can help me with this page?
Hemerson Carlin, also known as mersocarlin, is passionate and resourceful full-stack Software Engineer with 10+ years of experience focused on agile development, architecture and team building.
This is the space to share the things he likes, a couple of ideas and some of his work.