Update deepMapKeys.md
This commit is contained in:
@ -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.
|
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
|
```js
|
||||||
const deepMapKeys = (obj, f) => (
|
const deepMapKeys = (obj, f) => (
|
||||||
@ -23,12 +24,9 @@ const deepMapKeys = (obj, f) => (
|
|||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
'use strict';
|
|
||||||
const obj = {
|
const obj = {
|
||||||
foo:'1',
|
foo:'1',
|
||||||
isnull:null,
|
|
||||||
nested:{
|
nested:{
|
||||||
bar:'1',
|
|
||||||
child:{
|
child:{
|
||||||
withArray:[
|
withArray:[
|
||||||
{
|
{
|
||||||
@ -37,15 +35,12 @@ const obj = {
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
const upperKeysObj = deepMapKeys(obj, (key) => key.toUpperCase());
|
const upperKeysObj = deepMapKeys(obj, (key) => key.toUpperCase());
|
||||||
/*
|
/*
|
||||||
Formatted JSON Data
|
|
||||||
{
|
{
|
||||||
"FOO":"1",
|
"FOO":"1",
|
||||||
"ISNULL":null,
|
|
||||||
"NESTED":{
|
"NESTED":{
|
||||||
"BAR":"1",
|
|
||||||
"CHILD":{
|
"CHILD":{
|
||||||
"WITHARRAY":[
|
"WITHARRAY":[
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user