docs/reference/array/zip.md
Creates an array of tuples by bundling elements at the same index from multiple arrays.
const zipped = zip(...arrs);
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']]
arrs (Array<readonly T[]>): The arrays to bundle.(T[][]): Returns a new array where elements at the same index from each input array are bundled into tuples.