Created
January 5, 2022 16:33
-
-
Save MentalGear/51de081e32a7f872f5313494bff67904 to your computer and use it in GitHub Desktop.
Combine and deduplicate Arrays
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Note: Does only work with primities (numbers, strings) as objects/arrays, etc are saved by reference | |
// meaning even if the object is the same twice, the reference will be different and Set() will not have unique true values | |
// this could maybe be fixed by JSON.stringifying non-primitive values on save | |
export function mergeDedupeArrays(arrays) { | |
let combinedArrays = [] | |
for (let array of arrays) { | |
combinedArrays = combinedArrays.concat(array) | |
} | |
return [...new Set(combinedArrays)] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment