Prepare repository for merge

This commit is contained in:
Angelos Chalaris
2023-05-01 22:35:56 +03:00
parent fc4e61e6fa
commit b3ad01863a
578 changed files with 0 additions and 0 deletions

View File

@ -0,0 +1,25 @@
---
title: Uppercase object keys
type: snippet
tags: [object]
author: chalarangelo
cover: sofia-tram
dateModified: 2023-02-11T05:00:00-04:00
---
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, using `String.prototype.toUpperCase()` to uppercase the keys.
```js
const upperize = obj =>
Object.keys(obj).reduce((acc, k) => {
acc[k.toUpperCase()] = obj[k];
return acc;
}, {});
```
```js
upperize({ Name: 'John', Age: 22 }); // { NAME: 'John', AGE: 22 }
```