← All Exercises

Remove Array Duplicates

basicjavascript~10min

Background

Deduplication is critical in data cleaning, set operations, and preventing redundant processing of elements.

Problem

Write a function that takes an array and returns a new array with all duplicate values removed, preserving the order of first appearance.

Input

An array of primitive values (numbers, strings, booleans).

Output

A new array with duplicates removed, preserving first-occurrence order.

Sample tests

Sample 1

Input: [1, 2, 2, 3, 1, 4]
Expected: [1, 2, 3, 4]

Your solution

Learning objective

Learn to use Set for efficient deduplication and understand order preservation.