JavaScript

配列のマージ

More than 3 years have passed since last update.

メモ

var array1 = [1, 2, 3];
var array2 = [4, 5, 6];


//結合
var newArray = array1.concat(array2);

console.log(newArray);
=>[1, 2, 3, 4, 5, 6]

console.log(array1);
=>[1, 2, 3]


//破壊的結合
var ArrayLength = Array.prototype.push.apply(array1, array2);

console.log(ArrayLength)
=> 6

console.log(array1);
=> [1, 2, 3, 4, 5, 6]