Merge pull request #386 from Chalarangelo/lowercase-keys

[FEATURE] Add lowercaseKeys
This commit is contained in:
Angelos Chalaris
2017-12-29 15:37:01 +02:00
committed by GitHub
2 changed files with 17 additions and 0 deletions

16
snippets/lowercaseKeys.md Normal file
View File

@ -0,0 +1,16 @@
### lowercaseKeys
Creates a new object from the specified object, where all the keys are in lowercase.
Use `Object.keys()` and `Array.reduce()` to create a new object from the specified object.
Convert each key in the original object to lowercase, using `String.toLowerCase()`.
```js
const lowercaseKeys = obj =>
Object.keys(obj).reduce((acc,key) => {acc[key.toLowerCase()] = obj[key]; return acc;},{});
```
```js
const myObj = {Name: 'Adam', sUrnAME: 'Smith'};
const myObjLower = lowercaseKeys(myObj); // {name: 'Adam', surname: 'Smith'};
```

View File

@ -76,6 +76,7 @@ JSONToDate:date
JSONToFile:node JSONToFile:node
last:array last:array
lcm:math lcm:math
lowercaseKeys:object
mapObject:array mapObject:array
max:math max:math
median:math median:math