sudowork
08-14-2009, 04:11 PM
I'm creating an AJAX application where multiple users will be interacting with a single interface. I'm looking for a function of consolidating two different arrays, with common elements, into a single array.
For example:
var array1 = ['apple','orange','grape'];
var array2 = ['apple','grape','pear'];
var array3 = magicFunction(array1,array2);
//array3's contents = ['apple','orange','grape','pear']
Does this sound doable in a fairly fast manner, or am I going about this completely wrong?
I was thinking about just looping through both arrays and adding them to a third array, and during the second loop, if the element exists, don't add it.
For example:
var array1 = ['apple','orange','grape'];
var array2 = ['apple','grape','pear'];
var array3 = magicFunction(array1,array2);
//array3's contents = ['apple','orange','grape','pear']
Does this sound doable in a fairly fast manner, or am I going about this completely wrong?
I was thinking about just looping through both arrays and adding them to a third array, and during the second loop, if the element exists, don't add it.