Skip to content

Instantly share code, notes, and snippets.

@sinsunsan
Created April 20, 2018 09:56
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 sinsunsan/554024c0d09aafd2eb414ad409a2d184 to your computer and use it in GitHub Desktop.
Save sinsunsan/554024c0d09aafd2eb414ad409a2d184 to your computer and use it in GitHub Desktop.
deduplication of Arrays in js without lodash
// we concatenate projects thanks to the spread operator of ES6
const allProjects = [
...projectsB,
...projectsA
];
// we use the new Set object
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
// that cannot have duplicate items.
// and convert it back to an array
projectsUnion = Array.from(new Set(allProjects).values());
// As an alternative syntax
projectsUnion = [...new Set(allProjects)];
// but sometimes do not work with typescript...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment