✒️
Here are my favorite tips to land the software engineer interview.
Here are my favorite tips to land the software engineer interview.
How to Make a Shallow Copy of Array and Object in JavaScript
Published Aug 23, 2020
∙ Updated May 2, 2022
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 };