✒️
Start your developer blog today!
✉️
Questions?
Email me

How to Make a Shallow Copy of Array and Object in JavaScript

Aug 23, 2020 1 min read

Modern JavaScript has made shallow copying easier than ever. ES6 (ES2015) introduced the spread operator ..., which essentially dumps the contents of an array or object.

Copy an Array

const original = [1, 2, 3];
const copy = [ ...original ];

Copy an Object

const original = { 
  key1: 1,
  key2: 2
};
const copy = { ...original };

More JavaScript Articles