Skip to content

Instantly share code, notes, and snippets.

@uttarwarsandesh33
uttarwarsandesh33 / deepCopyRecursion.js
Last active September 12, 2021 14:47
Create deep copy with recursive method
//recursive method to create deep copy
function deepCopy(obj) {
if (null === obj || 'object' !== typeof obj) return obj;
switch (obj.constructor) {
case Boolean:
return new Boolean(obj);
case Number:
return new Number(obj);
@uttarwarsandesh33
uttarwarsandesh33 / deepCopy.js
Created April 27, 2021 17:20
Deep copy with JSON
const originalObject = {
string: 'primitive string',
stringObj: new String('string obj'),
number: 100,
numberObj: new Number(100),
bigInt: BigInt("9007199254740991"),
nan: NaN,
array: [1, 2, 3],
arrayObj: new Array(2),
bool: false,