Last active
September 10, 2024 05:44
-
-
Save mersanuzun/3e06a47aa9876eb8cb041f37f5506725 to your computer and use it in GitHub Desktop.
convert given nested object to the plain one
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
function convertPlainObject (nestedObj, baseKey = '', result = {}) { | |
Object.entries(nestedObj).forEach(([key, value]) => { | |
if (typeof value === 'object') { | |
return convertPlainObject(value, baseKey === '' ? key : `${baseKey}.${key}`, result); | |
} | |
result[`${baseKey ? `${baseKey}.` : ''}${key}`] = value; | |
}); | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment