I know it’s kind of late, but JavaScript has a convenient Array.prototype.concat()
method. It returns a value without modifying the original array.
Given array1 = [1, 2] & array2 = [3, 4]
:
let array3 = array1.concat(array2);
‘array3’ will be defined as [1, 2, 3, 4]
(this method is stackable, so you can do array1.concat(array2).concat(array3)...
In blocks you need to write your own method, as one is not in place. You could implement it something like this (pseudocode) :
function add_arrays(array1, array2)
define new_array = array1
for item in array do
new_array.push(item)
return new_array
Or alternatively (blocks) :