Last active
October 17, 2019 15:51
-
-
Save alperg/58c6ee8512cc434b4e373d37296326e4 to your computer and use it in GitHub Desktop.
Renaming Properties
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
// 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