( 19 Articles)
In order to merge (or concatenate) two, three, or more arrays in ES6, we can use the spread syntax.
const arrA = [1, 2, 3, 4, 5] const arrB = [6, 7, 8] const arrC = [9, 10] // merging const arrAll = [...arrA, ...arrB, ...arrC] // printing the result console.log(arrAll)
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
- Using the spread syntax does not change the existing arrays. It always returns a new array
- You can use any number of arrays, even only one.
- 2 Ways to Set Default Time Zone in Node.js
- [JS] Generate a random number between Min and Max and exclude a specific number