Q: How to concatenate arrays in JavaScript using Spread Operator?

JavaScript arrays

Answer:

The spread operator is a useful and quick syntax for adding items to arrays, combining arrays or objects.

let arr1 = [1, 2, 3];
let arr2 = [4, 5];

let newArray = [...arr1, ...arr2];

console.log(newArray); // Output: [1, 2, 3, 4, 5]

Spread Operator


    No comments found for this tutorial, be the first to leave a comment!

Answered by
Double

Last updated on
Sep 18, 2021

Share