Skip to content

Instantly share code, notes, and snippets.

@mersanuzun
Last active July 24, 2024 12:50
Show Gist options
  • Save mersanuzun/3e06a47aa9876eb8cb041f37f5506725 to your computer and use it in GitHub Desktop.
Save mersanuzun/3e06a47aa9876eb8cb041f37f5506725 to your computer and use it in GitHub Desktop.
convert given nested object to the plain one
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