JS

HOW TO JOIN ARRAYS IN JAVASCRIPT

var arrA = ["Jan", "Jon"],        arrB = ["Jay", "Joy"],        arrC = ["Jaz", "Joz"];   var combined = arrA.concat(arrB, arrC);

CONCAT ARRAYS

01

var arrA = ["Jan", "Jon"],        arrB = ["Jay", "Joy"],        arrC = ["Jaz", "Joz"];   var combined = [...arrA, ...arrB, ...arrC];

SPREAD OPERATOR

02

var arrA = ["Jan", "Jon"],        arrB = ["Jay", "Joy"],        arrC = ["Jaz", "Joz"];   var combined = arrA; for (let el of arrB) { combined.push(el); } for (let el of arrC) { combined.push(el); }

MANUAL LOOP AND PUSH

03

var arrA = ["Jan", "Jon"],        arrB = ["Jay", "Joy"];   Jan, Jay, Joy, Jon var combined = arrA; combined.splice(1, 0, ...arrB);

SPLICE ARRAY

04

var arrA = [1, 2, 3], arrB = [4, 5, 6];  ADD BOTH ARRAY - 5, 7, 9 var combined = arrA.map(   (v, i) => { return v + this[i]; }, arrB );

ARRAY MAP

05