Last active
May 2, 2019 11:46
-
-
Save Viktor19931/42b1374cf881a7c7654c9a756c8f59a6 to your computer and use it in GitHub Desktop.
merge two arrays and make data uniq by id
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
const mergeArray = (arr1, arr2) => { | |
let arr = [...arr1, ...arr2] | |
const uniqueArr = arr | |
.map(e => e.id) | |
.map((e, i, keysArr) => keysArr.indexOf(e) === i && i) | |
.filter(e => arr[e]).map(e => arr[e]); | |
return uniqueArr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment