This content originally appeared on CodeSource.io and was authored by Ariessa Norramli
In this article, you will learn how to clone an object in Javascript.
Let’s say you have an object named ‘a’.
var a = { name: "codesource.io" };
In order to clone an object, you can use the spread syntax ...
.
var a = { name: "codesource.io" };
var b = { ...a };
console.log(a);
console.log(b);
Note: The spread syntax ...
functions by shallow copying the properties and values of an object to another.
The post How to Clone An Object in Javascript appeared first on CodeSource.io.
This content originally appeared on CodeSource.io and was authored by Ariessa Norramli
Ariessa Norramli | Sciencx (2021-02-18T11:16:12+00:00) How to Clone An Object in Javascript. Retrieved from https://www.scien.cx/2021/02/18/how-to-clone-an-object-in-javascript/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.