DEV Community

loading...

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

Collapse
gobeli profile image
Etienne • Edited

It does work, but not for nested objects. i.e.:

const x = {
  foo: {
    bar: false
  }
}
const y = Object.assign({}, x);
console.log(x === y); // outputs false
console.log(x.foo === y.foo); // outputs true
Forem Open with the Forem app