DEV Community

Discussion on: How to Deep Clone an Array in JavaScript

Collapse
 
alinalapina profile image
Alina Lapina

In the last clone (recursive code) the function have to return a copy of item, {...item}, in order to create deep cloning, not the item reference.
The whole piece of code is:

const clone = (items) => items.map(item => Array.isArray(item) ? clone(item) : {...item});