How to Clone An Object in Javascript

In this article, you will learn how to clone an object in Javascript. Let’s say you have an object named ‘a’. In order to clone…

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

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


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » How to Clone An Object in Javascript." Ariessa Norramli | Sciencx - Thursday February 18, 2021, https://www.scien.cx/2021/02/18/how-to-clone-an-object-in-javascript/
HARVARD
Ariessa Norramli | Sciencx Thursday February 18, 2021 » How to Clone An Object in Javascript., viewed ,<https://www.scien.cx/2021/02/18/how-to-clone-an-object-in-javascript/>
VANCOUVER
Ariessa Norramli | Sciencx - » How to Clone An Object in Javascript. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/02/18/how-to-clone-an-object-in-javascript/
CHICAGO
" » How to Clone An Object in Javascript." Ariessa Norramli | Sciencx - Accessed . https://www.scien.cx/2021/02/18/how-to-clone-an-object-in-javascript/
IEEE
" » How to Clone An Object in Javascript." Ariessa Norramli | Sciencx [Online]. Available: https://www.scien.cx/2021/02/18/how-to-clone-an-object-in-javascript/. [Accessed: ]
rf:citation
» How to Clone An Object in Javascript | Ariessa Norramli | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.