Last active
November 27, 2019 10:16
-
-
Save mkhizeryounas/a4ccad00cb728cefba002f0a07dd065b 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
/** | |
* This example will convert all boolean values into string. | |
**/ | |
function parse(obj, parent) { | |
for (let key in obj) { | |
let value = obj[key]; | |
if (typeof value === "object") { | |
let tmpParent = Array.isArray(value)) ? [] : {}; | |
parent[key] = parse(value, tmpParent); | |
} else if (typeof value === "boolean") parent[key] = `${value}`; | |
else parent[key] = value; | |
} | |
return parent; | |
} | |
parse({name:true, l:"Khizer", arr: ["k",true, false,"l", true, {a:true, k: [{a:true, b:{k:1}}]}]}, {}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment