Cloning a JavaScript object vis Json Serialization - Javascript JSon

Javascript examples for JSon:JSon String

Description

Cloning a JavaScript object vis Json Serialization

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=( function() {//  w w  w .  j  a va 2  s  .  com

var user = {name: "Foo", email: "bar@baz.com" }
var user2 = JSON.parse(JSON.stringify(user))
user2.name = "Bar";
console.log(user.name + " " + user2.name);


    });

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials