Created
August 16, 2019 03:04
-
-
Save phatnguyenuit/ddcc68d00158f53429b1a02636fb7979 to your computer and use it in GitHub Desktop.
Convert Object Keys In JavaScript
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
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