Skip to content

Instantly share code, notes, and snippets.

@alperg
Last active October 17, 2019 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alperg/58c6ee8512cc434b4e373d37296326e4 to your computer and use it in GitHub Desktop.
Save alperg/58c6ee8512cc434b4e373d37296326e4 to your computer and use it in GitHub Desktop.
Renaming Properties
// By combining the techniques above, a function can be created to rename properties.
// Imagine there are some objects with an uppercase ID that should be lowercase.
// Start by destructuring ID out of the object. Then add it back as id while object is being spread.
const renamed = ({ ID, ...object }) => ({ id: ID, ...object });
const user = {
ID: 500,
name: "Bob Fossil"
};
renamed(user); // { id: 500, name: 'Bob Fossil' }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment