Skip to main content
9 events
when toggle format what by license comment
Dec 28, 2018 at 12:40 comment added dehart Not sure what the costs of indexOf() method are but this is probably the fastest ES5 compatible method. Also worth nothing that the variable length of arguments is not needed. This method is chainable. @slickplaid Loading a library is never an answer to a "how to do it in javascript" question. surely many libraries have a function to get this 7 lines job done.
Dec 7, 2018 at 10:19 comment added Techdive what is Array ? is it where your output is saved ? is it saved in Array ? I have one array that has multiple arrays inside it . Eg -> abc = [ ['a'], ['b'], ['c','d','e'] ] ...so will it be like Array.prototype.merge = function(abc) { //code }
Feb 19, 2015 at 16:52 comment added Cobra @slickplaid True, and it's quite a bit faster, even compared to the lodash/_ one. I'll probably end up switching my implementation at one point or another to something similar to yours. :D
Feb 18, 2015 at 14:14 comment added slickplaid @Cobra At the risk of sounding petty, running on Chrome 40.0.2214 (Latest as of 2/18/15), this answer is 53% slower than mine. OTOH IE11 seems not optimized for my answer at all. :) Chrome mobile is still rocking it, though. Honestly, if you're using lodash/_ which most of us should, the true answer is already pretty high up on this list. :)
Aug 8, 2014 at 16:14 comment added Cobra Excellent solution. I've updated the jsperf test posted above by @slickplaid (jsperf.com/merge-two-arrays-keeping-only-unique-values/3) and it looks like this is the fastest one of them.
May 4, 2014 at 11:18 comment added Doubidou var test = ['a', 'b', 'c']; console.log(test); will print ["a", "b", "c", merge: function]
Aug 22, 2011 at 18:44 history edited GAgnew CC BY-SA 3.0
added 80 characters in body
Aug 19, 2011 at 14:22 history edited GAgnew CC BY-SA 3.0
added 52 characters in body
Aug 19, 2011 at 13:34 history answered GAgnew CC BY-SA 3.0