Skip to content

Instantly share code, notes, and snippets.

@mkhizeryounas
Last active November 27, 2019 10:16
Show Gist options
  • Save mkhizeryounas/a4ccad00cb728cefba002f0a07dd065b to your computer and use it in GitHub Desktop.
Save mkhizeryounas/a4ccad00cb728cefba002f0a07dd065b to your computer and use it in GitHub Desktop.
/**
* 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