DEV Community

Cover image for JavaScript: Best way to remove duplicates in JS Array
Kristiyan Velkov
Kristiyan Velkov

Posted on • Edited on

3 1 1 1 1

JavaScript: Best way to remove duplicates in JS Array

Hello, folks!

1) Remove duplicates from an array using a Set

A Set is a collection of unique values. To remove duplicates from an array:

  • First, convert an array of duplicates to a Set. The new Set will implicitly remove duplicate elements.
  • Then, convert the set back to an array.
  • The following example uses a Set to remove duplicates from an array:
let dublicates = ['A', 'A', 'A', 'B', 'C', 'C'];
let uniqueChars = [...new Set(dublicates)];

Output:

[ 'A', 'B', 'C' ]

Enter fullscreen mode Exit fullscreen mode

Image description

linkedin


Image description

If you like my work and want to support me to work hard, please donate via:

Revolut website payment or use the QR code above.

Thanks a bunch for supporting me! It means a LOT 😍

SurveyJS custom survey software

Simplify data collection in your JS app with a fully integrated form management platform. Includes support for custom question types, skip logic, integrated CCS editor, PDF export, real-time analytics & more. Integrates with any backend system, giving you full control over your data and no user limits.

Learn more

Top comments (0)

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay