Skip to content

Instantly share code, notes, and snippets.

@Viktor19931
Last active May 2, 2019 11:46
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 Viktor19931/42b1374cf881a7c7654c9a756c8f59a6 to your computer and use it in GitHub Desktop.
Save Viktor19931/42b1374cf881a7c7654c9a756c8f59a6 to your computer and use it in GitHub Desktop.
merge two arrays and make data uniq by id
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