Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • 3
    I believe this is much cleaner than the accepted answer. Also it looks like filter is supported in ECMAScript 5.1 + which is pretty supported now.
    – Tom Fobear
    Commented Oct 17, 2017 at 18:56
  • 1
    this is so much more succinct.
    – Mox
    Commented Apr 22, 2020 at 2:31
  • 4
    one liner: const mergeUnique = (a, b) => a.concat(b.filter(v => a.indexOf(v) === -1))
    – mad.meesh
    Commented Sep 28, 2020 at 1:21
  • 3
    This does not remove dups from arr1, it only adds unique elements from arr2 Commented Sep 9, 2021 at 5:21
  • One can use findIndex for finding index of objects by their property values within the filter() function like so: const index = arr1.findIndex(i => i.id === item.id);
    – askepott
    Commented Feb 23, 2023 at 18:47