Tuesday, June 2, 2020

JavaScript Clone Object

Cloning a Object in JavaScript is not going to be StraightForward especailly if the Object contians Complex Objects and is not limited to primitive types.


  1.  Use Object.assign

           var newObject = Object.assign({}, oldObject);


      2. JSON way
          var newObject =  JSON.parse(JSON.stringify(oldObject));