Update deepMapKeys.md

This commit is contained in:
Angelos Chalaris
2018-12-10 11:49:38 +02:00
committed by GitHub
parent ea4284adf9
commit 8a5fc0bb9e

View File

@ -4,7 +4,8 @@ Deep maps an object keys.
Creates an object with the same values as the provided object and keys generated by running the provided function for each key.
Use Object.keys(obj) to iterate over the object's keys. Use Array.prototype.reduce() to create a new object with the same values and mapped keys using fn.
Use `Object.keys(obj)` to iterate over the object's keys.
Use `Array.prototype.reduce()` to create a new object with the same values and mapped keys using `fn`.
```js
const deepMapKeys = (obj, f) => (
@ -23,37 +24,31 @@ const deepMapKeys = (obj, f) => (
```
```js
'use strict';
const obj = {
foo:'1',
isnull:null,
nested:{
bar:'1',
child:{
withArray:[
{
grandChild:[ 'hello' ]
}
]
}
}
}
foo:'1',
nested:{
child:{
withArray:[
{
grandChild:[ 'hello' ]
}
]
}
}
};
const upperKeysObj = deepMapKeys(obj, (key) => key.toUpperCase());
/*
Formatted JSON Data
{
"FOO":"1",
"ISNULL":null,
"NESTED":{
"BAR":"1",
"CHILD":{
"WITHARRAY":[
{
"GRANDCHILD":[ 'hello' ]
}
]
}
}
"FOO":"1",
"NESTED":{
"CHILD":{
"WITHARRAY":[
{
"GRANDCHILD":[ 'hello' ]
}
]
}
}
}
*/
```