JavaScript program to clone an object:

Created with Sketch.

JavaScript program to clone an object:

let originalObject = {name: "John", age: 30};
let clonedObject = Object.assign({}, originalObject);

console.log(clonedObject);

Alternatively, you can use the spread operator (...) to clone an object:

let originalObject = {name: "John", age: 30};
let clonedObject = {...originalObject};

console.log(clonedObject);

Leave a Reply

Your email address will not be published. Required fields are marked *