ES5 provides concat() Array method to concatenate arrays. ES6 spread operator converts contents of operand elements into Array.

Using ES5

Here we are using concat method
var arr1 = ['a', 'b'];
var arr2 = ['c'];
var arr3 = ['d', 'e'];

var newArr = arr1.concat(arr2, arr3);
console.log(newArr);
// [ 'a', 'b', 'c', 'd', 'e' ]

Using ES6

Here we are using spread operator. It converts contents of operand elements into Array
const arr1 = ['a', 'b'];
const arr2 = ['c'];
const arr3 = ['d', 'e'];

console.log([...arr1, ...arr2, ...arr3]);
// [ 'a', 'b', 'c', 'd', 'e' ]
Click here to see DEMO

0 comments:

Blogroll

Catagories

Popular posts