Skip to content

Instantly share code, notes, and snippets.

@MentalGear
Created January 5, 2022 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MentalGear/51de081e32a7f872f5313494bff67904 to your computer and use it in GitHub Desktop.
Save MentalGear/51de081e32a7f872f5313494bff67904 to your computer and use it in GitHub Desktop.
Combine and deduplicate Arrays
// 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