Since Objects in JavaScript are reference values, you cant just Copy Using the =. But no worries, here are 3 different ways for you to Clone an Object
- Spread
- Object.assign
- JSON
const food = { beef: '🥩', bacon: '🥓' } // "Spread" { ...food } // "Object.assign" Object.assign({}, food) // "JSON" JSON.parse(JSON.stringify(food)) // RESULT: // { beef: '🥩', bacon: '🥓' }

Top comments (0)