Created
November 5, 2021 15:25
-
-
Save crossan007/c0351708632fcba0a52829485bbaff5c to your computer and use it in GitHub Desktop.
Render JavaScript object to a string; include all properties and sub-objects.
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
function showProps(obj, objName) { | |
var result = ``; | |
for (var i in obj) { | |
// obj.hasOwnProperty() is used to filter out properties from the object's prototype chain | |
if (obj.hasOwnProperty(i)) { | |
if (typeof obj[i] != "object"){ | |
result += `${objName}.${i} = ${obj[i]}\n`; | |
} | |
else { | |
result += `${objName}.${i} = ${showProps(obj[i],objName+"."+i)}\n`; | |
} | |
} | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment