Skip to content

How To Merge Two Arrays in JavaScript

Posted in Education, and WhoCodeFirst

const one = [`aaa`, `bbb`, `ccc`]
const two = [`ddd`, `eee`, `fff`]

You have the above arrays.
How will you merge those into a single array?

You can use concat method.
This method will work in older browsers also.

const megaArray = one.concat(two)

There is a new way to do this.
You can use the spread operator in JavaScript.

const megaArray = [...one, ...two]

Happy Learning! 😇

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *