๐—จ๐˜€๐—ฒ ๐—ฆ๐—ฒ๐˜ ๐—ณ๐—ผ๐—ฟ ๐—จ๐—ป๐—ถ๐—พ๐˜‚๐—ฒ ๐——๐—ฎ๐˜๐—ฎ

You work with lists in JavaScript. User IDs. Emails. Search results. These lists often have duplicates.

Use a Set object. It stores unique values. It removes duplicates automatically.

Example: const numbers = [1, 2, 2, 3, 4, 4]; const cleanNumbers = [...new Set(numbers)]; // Result: [1, 2, 3, 4]

This pattern cleans data fast. Skip loops. Skip manual checks.

Use it for:

Check if a value exists with .has(). const tags = new Set(); tags.add("js"); tags.has("js"); // true

Stick to arrays if you need order or indexes. Use Set for uniqueness. Your code stays clean.

Source: https://dev.to/a2nof/maybe-you-should-use-set-1j5n