All articles
javascript

Filter unique elements from an Array using modern JavaScript (ES6)

Share this article

Share on LinkedIn Share on X (formerly Twitter)

Today I was trying to organize some scripts, where I have many lines of text and I need to eliminate duplicate lines.

I knew that this can be done with Array.reduce() and using Set of EcmaScript6.

This is the smallest one I have ended up with:

const arr = ['Hello!', 'Utopian', 'Dev', 'Utopian', 'Author'];
 
const unique1 = [...new Set(arr1)]; // ['Hello!','Utopian','Dev','Author']

Comments