Go to repository

Function unflatten

Un-Flatten the given object. Given an object without nested elements, but whose keys represent paths in a nested elements object, return an object that has nested objects in it. This the reverse of flatten, in such a way that this complies.

unflatten({
'a.a1': 1,
'a.a2': 2,
'b.b1.b1i': 'hello',
'b.b1.b1ii': 'world'
});
// this will yield:
{
a: {
a1: 1,
a2: 2
},
b: {
b1: {
b1i: 'hello',
b1ii: 'world'
}
}
}

Additional options may be passed, such as which character is used as a delimiter, or the maximum depth level.

Type Parameters

  • TTarget extends Record<string, any>
  • TResult extends Record<string, any>

Parameters

Returns TResult

The unflattened object

""