Uppercase object keys
JavaScript, Object · Feb 11, 2023

Converts all the keys of an object to upper case.
- Use
Object.keys()
to get an array of the object's keys. - Use
Array.prototype.reduce()
to map the array to an object, usingString.prototype.toUpperCase()
to uppercase the keys.
const upperize = obj =>
Object.keys(obj).reduce((acc, k) => {
acc[k.toUpperCase()] = obj[k];
return acc;
}, {});
upperize({ Name: 'John', Age: 22 }); // { NAME: 'John', AGE: 22 }