Created
December 27, 2024 19:03
-
-
Save GianfrancoFrau/3538bd204190b254ed4454622d94eb4d to your computer and use it in GitHub Desktop.
This file contains hidden or 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 flattenObject = (obj, final, prefix) => { | |
Object.keys(obj).map((prop) => { | |
const current = obj[prop]; | |
const p = prefix ? prefix + '.' + prop : prop; | |
if (typeof current !== "object") { | |
final[p] = current; | |
} else if (Array.isArray(current)) { | |
final[p] = JSON.stringify(current); | |
} else { | |
return flattenObject(current, final, p); | |
} | |
}); | |
return final; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment