Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,851 questions

51,772 answers

573 users

How to clone an object in JavaScript

2 Answers

0 votes
const user = {
  id: 83829,
  name: 'Tom'
};
 
const clone_user = { ...user };
 
  
console.log(clone_user.id);
console.log(clone_user.name);
 
 
 
 
/*
run:
           
83829
"Tom"
     
*/

 



answered Nov 6, 2019 by avibootz
edited Mar 13, 2022 by avibootz
0 votes
const o = {
  id: 3467,
  lang: "javascript",
};
 
const cloneObject = { ...o };
 
console.log(cloneObject);
 
o.id = 9817;
 
console.log(cloneObject);
 
 
     
     
/*
run:
     
{
  id: 3467,
  lang: "javascript"
}
{
  id: 3467,
  lang: "javascript"
}
     
*/

 



answered Jan 26, 2021 by avibootz
edited Mar 13, 2022 by avibootz

Related questions

1 answer 156 views
1 answer 122 views
1 answer 146 views
2 answers 152 views
152 views asked Mar 13, 2022 by avibootz
2 answers 116 views
116 views asked Mar 13, 2022 by avibootz
1 answer 104 views
104 views asked Jun 4, 2016 by avibootz
3 answers 101 views
...