Skip to content

Instantly share code, notes, and snippets.

@iceener
Created May 13, 2020 21:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iceener/ac089d21215f3c2d4adcd0ea39812974 to your computer and use it in GitHub Desktop.
Save iceener/ac089d21215f3c2d4adcd0ea39812974 to your computer and use it in GitHub Desktop.
// Rename object keys
const renameKeys = (keysMap, obj) =>
Object.keys(obj).reduce(
(acc, key) => ({
...acc,
...{ [keysMap[key] || key]: obj[key] },
}),
{}
);
const obj = { name: 'overment' };
renameKeys({ name: 'nickname' });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment