API reference › @evolu/common › Array › zipArray
Call Signature
function zipArray<T>(
arrays: T,
): readonly [Readonly<ZipArrayResult<T>>, Readonly<ZipArrayResult<T>>];
Defined in: packages/common/src/Array.ts:944
Combines multiple arrays into an array of tuples.
Uses "shortest" mode — stops at the shortest input array. Preserves non-empty type when all input arrays are non-empty. See the TC39 Array.zip proposal for the pattern this follows.
Zipping to the shortest input
import {
assertEqual,
assertType,
zipArray,
type NonEmptyReadonlyArray,
} from "@evolu/common";
const pairs = zipArray([
[1, 2, 3],
["a", "b", "c"],
]);
assertEqual(pairs, [
[1, "a"],
[2, "b"],
[3, "c"],
]);
assertEqual(
zipArray([
[1, 2],
["a", "b", "c"],
[true, false],
]),
[
[1, "a", true],
[2, "b", false],
],
);
assertType<NonEmptyReadonlyArray<Readonly<[number, string]>>, typeof pairs>();
Call Signature
function zipArray<T>(arrays: T): readonly Readonly<ZipArrayResult<T>>[];
Defined in: packages/common/src/Array.ts:948
Possibly empty arrays.