Categories
JavaScript Answers

How to join or combine two arrays to concatenate into one array with JavaScript?

Spread the love

Sometimes, we want to join or combine two arrays to concatenate into one array with JavaScript.

In this article, we’ll look at how to join or combine two arrays to concatenate into one array with JavaScript.

How to join or combine two arrays to concatenate into one array with JavaScript?

To join or combine two arrays to concatenate into one array with JavaScript, we can use the spread operator.

For instance, we write

const a = ["a", "b", "c"];
const b = ["d", "e", "f"];

const c = [...a, ...b];

to combine the entries in a and b into array c by spreading the values in them into c with ....

Therefore, c is

["a", "b", "c", "d", "e", "f"]

Conclusion

To join or combine two arrays to concatenate into one array with JavaScript, we can use the spread operator.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

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