Travis build: 1951
This commit is contained in:
@ -5,12 +5,14 @@ Replaces the names of multiple object keys with the values provided.
|
||||
Use `Object.keys()` in combination with `Array.reduce()` and the spread operator (`...`) to get the object's keys and rename them according to `keysMap`.
|
||||
|
||||
```js
|
||||
const renameKeys = (keysMap, obj) => Object
|
||||
.keys(obj)
|
||||
.reduce((acc, key) => ({
|
||||
...acc,
|
||||
...{ [keysMap[key] || key]: obj[key] }
|
||||
}), {});
|
||||
const renameKeys = (keysMap, obj) =>
|
||||
Object.keys(obj).reduce(
|
||||
(acc, key) => ({
|
||||
...acc,
|
||||
...{ [keysMap[key] || key]: obj[key] }
|
||||
}),
|
||||
{}
|
||||
);
|
||||
```
|
||||
|
||||
```js
|
||||
|
||||
Reference in New Issue
Block a user