Both JavaScript code achieves the same task of merging the second array into the first one. I have come across various sources claiming that Option 2 is more memory efficient.
Is there a way or a tool available for me to verify and actually see if the memory usage in Option 2 is lower?
Option 1
//Consumes a large amount of memory
var array1 = [1, 2, 3];
var array2 = [4, 5, 6];
console.log(array1.concat(array2));
Option 2
//Reduces memory usage
var array1 = [1, 2, 3];
var array2 = [4, 5, 6];
console.log(array1.push.apply(array1, array2));
I attempted to use this method from with node.js code, but it wasn't very helpful. I also experimented with https://github.com/paulirish/memory-stats.js but it doesn't seem to work as expected.