JavaScript: How to join / combine two arrays to concatenate into one array?
Solution 1:
var a = ['a','b','c'];
var b = ['d','e','f'];
var c = a.concat(b); //c is now an an array with: ['a','b','c','d','e','f']
console.log( c[3] ); //c[3] will be 'd'
Solution 2:
Using modern JavaScript syntax - spread operator:
const a = ['a', 'b', 'c'];
const b = ['d', 'e', 'f'];
const c = [...a, ...b]; // c = ['a', 'b', 'c', 'd', 'e', 'f']
It is also the fastest way to concatenate arrays in JavaScript today.