connect tow lists javascript code example
Example 1: javascript array concat spread operator
const arr1 = [1,2,3]
const arr2 = [4,5,6]
const arr3 = [...arr1, ...arr2] //arr3 ==> [1,2,3,4,5,6]
Example 2: javascript concat two arrays
//ES6
const array3 = [...array1, ...array2];
Example 3: js combine two arrays
const letters = ['a', 'b', 'c'];
const numbers = [1, 2, 3];
letters.concat(numbers);
// result in ['a', 'b', 'c', 1, 2, 3]
Example 4: join two arrays javascript
// using push and apply to return the same array
const arr1 = ['a', 'b'];
const arr2 = ['c', 'd'];
arr1.push.apply(arr1, arr2);
console.log(arr1) // ['a', 'b', 'c', 'd']