Categories
JavaScript Answers

How to copy all items from one array into another with JavaScript?

Spread the love

To copy all items from one array into another with JavaScript, we use the spread operator.

For instance, we write

const objArray = [
  { name: "first" },
  { name: "second" },
  { name: "third" },
  { name: "fourth" },
];
const clonedArr = [...objArray];

to use the spread operator to spread the objArray entries into a new array by copying each entry.

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 *