Skip to content

Instantly share code, notes, and snippets.

@chkilel
Created February 11, 2022 11:21
Show Gist options
  • Save chkilel/dd69044b2f6c795d8ffecc7678f81231 to your computer and use it in GitHub Desktop.
Save chkilel/dd69044b2f6c795d8ffecc7678f81231 to your computer and use it in GitHub Desktop.
// Concat two arrays of objects and keep unique values
// Values from arr1 will be kept if exist in arr2, comparison made on `key`
// object {key: 1, label: '..', ....}
const unique = [...arr1, ...arr2].filter(
(item, index, self) => self.findIndex((t) => t.key === item.key) === index
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment