VDL Plugin SDK

unzip

Import from @varavel/vdl-plugin-sdk/utils/arrays.

function unzip<T>(zipped): Unzip<T>;

Gathers elements in the same position in an internal array from a grouped array of elements and returns them as a new array.

The returned array's length matches the longest nested array. Missing positions in shorter arrays are filled with undefined.

Type Parameters

Type ParameterDescription
T extends unknown[]The type of elements in the nested array.

Parameters

ParameterTypeDescription
zippedreadonly [...T[]][]The nested array to unzip.

Returns

Unzip<T>

A new array of unzipped elements.

Example

const zipped = [['a', true, 1],['b', false, 2]];
const result = unzip(zipped);
// result will be [['a', 'b'], [true, false], [1, 2]]