Get the unique elements from an array

Given an array with duplicate elements, return only the unique elements from an array:

function uniqueElements(a) {
	return [...new Set(a)]
}

const uniques = uniqueElements([1, 2, 2, 3, 3, 3]);
// [1, 2, 3]

Related MDN Documentation

Broader Topics Related to JavaScript Recipe: Get the unique elements from an array

JavaScript (and TypeScript) recipes

Quick and easy to copy recipes for JavaScript and TypeScript

JavaScript Recipe: Get the unique elements from an array Knowledge Graph