Function unflatten

  • Reconstructs a nested object from a flattened one using a delimiter. Numeric keys are automatically treated as array indices so arrays are recreated correctly.

    Parameters

    • object: Record<string, any>

      The flattened object.

    • delimiter: string = "."

      The string delimiter used to split keys.

    Returns Record<string, any>

    The nested (unflattened) object.

    const obj = { 'a.0': 1, 'a.1': 2 };
    unflatten(obj);
    // => { a: [1, 2] }