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/zip.md.

zip es-toolkit

Creates an array of tuples by bundling elements at the same index from multiple arrays.

const zipped = zip(...arrs);

Usage

zip(...arrs)

Use zip when you want to bundle elements at the same position from multiple arrays together. It returns a new array where elements at the same index from each array are bundled into tuples.

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

// Bundle two arrays.
zip([1, 2, 3], ['a', 'b', 'c']);
// Returns: [[1, 'a'], [2, 'b'], [3, 'c']]

// Bundle three arrays.
zip([1, 2], ['a', 'b', 'c'], [true, false]);
// Returns: [[1, 'a', true], [2, 'b', false], [undefined, 'c', undefined]]

If the arrays have different lengths, it adjusts to the longest array's length. Empty positions in shorter arrays are filled with undefined.

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

zip([1, 2], ['a', 'b', 'c', 'd']);
// Returns: [[1, 'a'], [2, 'b'], [undefined, 'c'], [undefined, 'd']]

Parameters

arrsArray<readonly T[]>required

The arrays to bundle.

Returns

Returns a new array where elements at the same index from each input array are bundled into tuples.

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.