I have an array with duplicate values.
I want to create a Set to get the different values ββof this array and delete or create a new array that will have the same MINUS data as the elements needed to create the Set.
This is not just removing duplicates, but removing SINGLE records of each individual value in the original array
Something like this works, but I wonder if there is a more direct approach:
let originalValues = [ 'a', 'a', 'a', 'b', 'b', 'c', 'c', 'd' ]; let distinct = new Set(originalValues); /* distinct -> { 'a', 'b', 'c', 'd' } */ // Perhaps originalValues.extract(distinct) ?? for (let val of distinct.values()) { const index = originalValues.indexOf(val); originalValues.splice(index, 1); } /* originalValues -> [ 'a', 'a', 'b', 'c' ]; */
source share