freeCodeCamp Challenge Guide: Deepcopy

Deepcopy


Solutions

Solution 1 (Click to Show/Hide)
function deepcopy(obj) {
  return JSON.parse(JSON.stringify(obj));
}

First convert the object to a JSON string, then parse the string to build the object

1 Like