Resolves #1176
This commit is contained in:
@ -12,12 +12,12 @@ Otherwise, it adds the appropriate prefixed key-value pair to the accumulator ob
|
||||
You should always omit the second argument, `prefix`, unless you want every key to have a prefix.
|
||||
|
||||
```js
|
||||
const flattenObject = (obj, prefix = '') =>
|
||||
const flattenObject = (obj, prefix = '') =>
|
||||
Object.keys(obj).reduce((acc, k) => {
|
||||
const pre = prefix.length ? prefix + '.' : '';
|
||||
if (typeof obj[k] === 'object' && obj[k] !== null && Object.keys(obj[k]).length > 0) Object.assign(acc, flattenObject(obj[k], pre + k));
|
||||
else acc[pre + k] = obj[k];
|
||||
return acc;
|
||||
const pre = prefix.length ? prefix + '.' : '';
|
||||
if (typeof obj[k] === 'object' && obj[k] !== null && Object.keys(obj[k]).length > 0) Object.assign(acc, flattenObject(obj[k], pre + k));
|
||||
else acc[pre + k] = obj[k];
|
||||
return acc;
|
||||
}, {});
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user