Skip to content

Instantly share code, notes, and snippets.

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