For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /reference/array/unzip.md.

unzip es-toolkit

Unpacks grouped arrays and creates new arrays by gathering elements at the same position.

const unzippedArrays = unzip(zipped);

Usage

unzip(zipped)

Use unzip when you want to create new arrays by collecting elements at the same index from a 2D array where multiple arrays are grouped together. It's the opposite operation of zip.

import { unzip } from 'es-toolkit/array';

// Unpack arrays grouped with strings, booleans, and numbers.
const zipped = [
  ['a', true, 1],
  ['b', false, 2],
  ['c', true, 3],
];
const result = unzip(zipped);
console.log(result);
// [['a', 'b', 'c'], [true, false, true], [1, 2, 3]]

// Unpack arrays grouped with user information.
const users = [
  ['john', 30, 'engineer'],
  ['jane', 25, 'designer'],
  ['bob', 35, 'manager'],
];
const [names, ages, roles] = unzip(users);
console.log(names); // ['john', 'jane', 'bob']
console.log(ages); // [30, 25, 35]
console.log(roles); // ['engineer', 'designer', 'manager']

The returned array's length matches the longest nested array, and missing positions from shorter arrays are filled with undefined.

import { unzip } from 'es-toolkit/array';

const mixed = [[1, 'a'], [2, 'b', true], [3]];
const result = unzip(mixed);
console.log(result);
// [[1, 2, 3], ['a', 'b', undefined], [undefined, true, undefined]]

Passing an empty array returns an empty array.

import { unzip } from 'es-toolkit/array';

const empty = unzip([]);
console.log(empty); // []

Parameters

zippedReadonlyArray<[...T]>required

A 2D array where multiple arrays are grouped together to be unpacked.

Returns

New arrays where elements at the same position are grouped together. If the original arrays have different lengths, empty positions in shorter arrays are filled with undefined.

Unzip<T>
Source: es-toolkit

Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.