structuredClone() in Javascript
In JavaScript, the structuredClone() method is used to create a deep copy of a JavaScript object, including nested objects and arrays. This method is similar to JSON.parse(JSON.stringify(object)), but it can handle more complex data types such as Date, RegExp, Map, Set, and cyclic object references, which are not supported by JSON.stringify().
Get Zeeshan Siddique’s stories in your inbox
Join Medium for free to get updates from this writer.
Feature in Web Worker
The structuredClone() method in JavaScript is actually not a built-in method of the language. The structuredClone() method is a part of the HTML5 Web Workers API and is used specifically within the context of web workers to clone objects for inter-worker communication.
Example:
const mainObject = {
name: 'Zeeshan',
age: 24,
familyMembers: ['Waleed', 'Zaid'],
address: {
city: 'Lahore',
country: 'Pakistan'
}
};
// Create a deep copy of the main (original) object
const clonedObject = structuredClone(mainObject);
console.log(clonedObject);




