JavaScript Tricks

De-duplicate Array

Given an array of non-unique values, you can de-duplicate the values in the array by converting it into a javascript set, new Set(). By definition, a "Set" contains only unique values so the constructor automatically removes any duplicate values.
const arrayWithDups = ["cat", "dog", "cat", "dog", "bat"];

const uniqueArray = [...new Set(arrayWithDups)]
// uniqueArray => ["cat", "dog", "bat"]
arrow_back

Previous

CSS Useful(misc.)

Next

Immer.js State Library
arrow_forward