July 19, 2007 – 2:36am Javascript Array Merge: array_merge

Using protoype.js I discovered a quick way to merge to arrays in javascript:

function array_merge(one, two) {
  one.push(two);
  return one.flatten();
}

This definitely beats the alternative of iterating through the second array by hand and adding it to the first. Any comments or suggestions are welcome.

Posted in  Web Development   |     |  delicious  Digg

2 Responses to “Javascript Array Merge: array_merge”

  1. You can do this even quicker!

    one = one.concat(two);

    Job done!

    By Rumble on Aug 7, 2007

  2. concat is KING

    By Scott Meves on Jun 5, 2008

Post a Comment

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word