concatenate javascript array code example
Example 1: concatenate javascript array
const fruits = ['apple', 'orange', 'banana'];
const joinedFruits = fruits.join();
console.log(joinedFruits);
Example 2: merge array in js
var array1 = ["Rahul", "Sachin"];
var array2 = ["Sehwag", "Kohli"];
var output = array1.concat(array2);
console.log(output);
var array1 = ["Dravid", "Tendulkar"];
var array2 = ["Virendra", "Virat"];
var output = [...array1, ...array2];
console.log(output);
Example 3: concat array javascript
const letters = ['a', 'b', 'c'];
const numbers = [1, 2, 3];
const newArray = letters.concat(numbers);
Example 4: js join two arrays
[1,2,3].concat([4,5,6])
Example 5: join two arrays javascript
const arr1 = ['a', 'b'];
const arr2 = ['c', 'd'];
arr1.push.apply(arr1, arr2);
console.log(arr1)