DEV Community

Discussion on: Best way to copy an object in JavaScript?

Collapse
 
francormm profile image
francoRMM

I use spread to copy and assign a new value to the old object

const copy=old=>{
  return {...old};
}

const add=(old,val)=>{
  return {...old,...val};
}

but this is the same as Object.assign({}, obj);, is not a deep copy.