79319492

Date: 2024-12-31 08:25:00
Score: 1
Natty:
Report link

In 2024, you can use structuredClone, majorly for arrays and objects. It provides a deep clone of the given value. For shallow copy you can use the above answer given by @xynon - https://stackoverflow.com/a/60460458/11410210, which I would suggest to use as per requirement.

structuredClone example usage:

const originalArray = [1, 2, 3];
const newArray = structuredClone(originalArray);
newArray.push(4);

console.log('originalArray', originalArray); // [1, 2, 3]
console.log('newArray', newArray); // [1, 2, 3, 4]

Reasons:
  • Blacklisted phrase (1): stackoverflow
  • Whitelisted phrase (-1.5): you can use
  • Has code block (-0.5):
  • User mentioned (1): @xynon
  • Low reputation (1):
Posted by: Vishakha