Last active
February 17, 2023 00:58
-
-
Save roman-bgonz/d4ed51c4c8fd07c08d71a4507ecad1e7 to your computer and use it in GitHub Desktop.
Uppercase object key name
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 obj = {name: "Name", position: "developer"} | |
const keyToUpper = (obj: any) => | |
Object.keys(obj).reduce((acc, k) => { | |
acc[k.toUpperCase()] = obj[k]; | |
return acc; | |
}, {}); | |
console.log(keyToUpper(obj)) | |
// Expected result | |
{NAME: "Name", POSITION: "developer"} | |
// Stackblitz https://stackblitz.com/edit/typescript-h3erat?file=index.ts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment