Apply new format to snippets and template
This commit is contained in:
@ -5,9 +5,9 @@ tags: object,advanced
|
||||
|
||||
Unflatten an object with the paths for keys.
|
||||
|
||||
Use `Object.keys(obj)` combined with `Array.prototype.reduce()` to convert flattened path node to a leaf node.
|
||||
If the value of a key contains a dot delimiter (`.`), use `Array.prototype.split('.')`, string transformations and `JSON.parse()` to create an object, then `Object.assign()` to create the leaf node.
|
||||
Otherwise, add the appropriate key-value pair to the accumulator object.
|
||||
- Use `Object.keys(obj)` combined with `Array.prototype.reduce()` to convert flattened path node to a leaf node.
|
||||
- If the value of a key contains a dot delimiter (`.`), use `Array.prototype.split('.')`, string transformations and `JSON.parse()` to create an object, then `Object.assign()` to create the leaf node.
|
||||
- Otherwise, add the appropriate key-value pair to the accumulator object.
|
||||
|
||||
```js
|
||||
const unflattenObject = obj =>
|
||||
@ -30,4 +30,4 @@ const unflattenObject = obj =>
|
||||
|
||||
```js
|
||||
unflattenObject({ 'a.b.c': 1, d: 1 }); // { a: { b: { c: 1 } }, d: 1 }
|
||||
```
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user