Created
July 22, 2017 16:30
-
-
Save Xhamps/fbe07f8c290c9ad857cb8d83401dcd75 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const j = {a: 1, b: 2, c: { d: 2}, e: { f: { g: 10} } }; | |
function xhamps(obj) { | |
const creatNewObj = (obj) => { | |
return Object.keys(obj).reduce((r, key) => { | |
r[key] = (typeof obj[key] === 'object')? creatNewObj(obj[key]) : obj[key]; | |
return r; | |
},{}); | |
}; | |
const newData = creatNewObj(obj); | |
return newData; | |
} | |
console.log(j); | |
const newXhamps = xhamps(j); | |
console.log(newXhamps); | |
newXhamps.a = 100; | |
newXhamps.e.f.g = 3000; | |
console.log(newXhamps); | |
console.log(j); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment