Timeline for How to merge two arrays in JavaScript and de-duplicate items
Current License: CC BY-SA 4.0
20 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Nov 25, 2019 at 16:59 | history | edited | dota2pro | CC BY-SA 4.0 |
Converting Code to Demo
|
Jun 20, 2019 at 17:24 | comment | added | user210757 |
why not just return [...new Set(arr)]; rather than return [...new Set([].concat(...arr))]; ? Not saying it is wrong just wondering why you have to do this
|
|
Apr 21, 2019 at 17:26 | comment | added | Ben Carp | This is very elegant. Unfortunately Typescript doesn't support this yet. stackoverflow.com/questions/33464504/… | |
Aug 10, 2018 at 14:38 | comment | added | connexo |
@HenryBlyth So what do you think ...arr is? What's the point in using Array.from instead of the spread operator if you're still using ...arr inside?
|
|
May 3, 2018 at 15:35 | comment | added | bArmageddon | The current accepted answer refers to ES6 without this elegant answer, it should be revised to include it | |
Oct 18, 2017 at 6:39 | history | edited | Peter Mortensen | CC BY-SA 3.0 |
Active reading.
|
Apr 8, 2017 at 20:37 | comment | added | 7vujy0f0hy | @Bergi: No, an answer ☺. You said “make it”, so I made it... and improved even more. | |
Apr 8, 2017 at 18:11 | comment | added | Bergi | @7vujy0f0hy Is that a question? | |
Apr 8, 2017 at 18:01 | comment | added | 7vujy0f0hy |
@Bergi: var mergeDeduplicate = (...arrayOfArrays) => [...new Set([].concat(...arrayOfArrays))];
|
|
Feb 16, 2017 at 12:08 | comment | added | Henry Blyth |
Array.from can be used instead of spread operator: Array.from(new Set([].concat(...arr)))
|
|
Sep 21, 2016 at 19:43 | comment | added | Cezar Augusto | Hard to say that this should be the accepted answer since the question is from 2009. But yes, this not only is more "performant" but also "elegant" | |
May 18, 2016 at 22:49 | comment | added | MusikAnimal |
Babel only converts syntax. You need a transform for Set to fully work in IE10 and Safari, which can be messy
|
|
May 4, 2016 at 20:30 | history | edited | cmcculloh | CC BY-SA 3.0 |
Remove Array in favor of [], and add guidance on how to be able to use in your app today.
|
Feb 19, 2016 at 14:54 | comment | added | Bergi |
Um, the Array constructor has no static concat method? (Proprietary FF ignored). You should make that [].concat(...arr) .
|
|
Feb 19, 2016 at 14:52 | comment | added | Bergi |
@jedd.ahyoung: make it mergeDedupe(...arr) and you can call it like mergeDedupe(array1, array2) which is exactly what the OP wants.
|
|
Feb 12, 2016 at 16:48 | comment | added | user677526 | This isn't quiiite the same as the OP's question (this seems to be more of a flatmap than anything) but upvote because it's awesome. | |
Feb 8, 2015 at 16:55 | history | edited | Adria | CC BY-SA 3.0 |
added 85 characters in body
|
Jan 21, 2015 at 23:08 | comment | added | mmm | This should be added to the accepted answer. This solution is much more efficient and much more elegant than what's currently possible but it's what we'll inevitably be able to do (and should do to keep up in this field). | |
Dec 28, 2014 at 2:28 | history | edited | Adria | CC BY-SA 3.0 |
added 112 characters in body
|
Dec 27, 2014 at 6:28 | history | answered | Adria | CC BY-SA 3.0 |