pbojinov
8/14/2013 - 8:30 PM

merge two arrays using concat() or push.

merge two arrays using concat() or push.

/**
 * Concat
 */
var mergeTo = [4,5,6],
    mergeFrom = [7,8,9];
    
mergeTo = Array.prototype.concat(mergeTo, mergeFrom);
mergeTo; // is: [4, 5, 6, 7, 8, 9]
 
/**
 * Push
 */
var mergeTo = [4,5,6],
    mergeFrom = [7,8,9];
    
Array.prototype.push.apply(mergeTo, mergeFrom);
mergeTo; // is: [4, 5, 6, 7, 8, 9]

/**
 * TODO: run performance test
 */