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