Created
April 20, 2018 09:56
-
-
Save sinsunsan/554024c0d09aafd2eb414ad409a2d184 to your computer and use it in GitHub Desktop.
deduplication of Arrays in js without lodash
This file contains 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
// 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