Created
August 16, 2019 03:04
-
-
Save phatnguyenuit/2bc0d1f228119f899e3b88f6dce7d913 to your computer and use it in GitHub Desktop.
Convert Object Keys In JavaScript
This file contains hidden or 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
| const convertObjectKeys = (obj, convertFn) => { | |
| let result = {}; | |
| for (const key in obj){ | |
| result[convertFn(key)] = obj[key]; | |
| } | |
| return result; | |
| } | |
| const upperCase = str => str.toUpperCase(); | |
| var obj ={a: 100}; | |
| convertKey(obj, upperCase); | |
| // {A: 100} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment