Skip to main content

latest
Works with
It is unknown whether this package works with Node.js, Deno, Browsers, Cloudflare Workers, Bun
It is unknown whether this package works with Node.js
It is unknown whether this package works with Deno
It is unknown whether this package works with Browsers
It is unknown whether this package works with Cloudflare Workers
It is unknown whether this package works with Bun
JSR Score70%
Downloads1/wk
Published2 years ago (0.215.0)
function zip
zip<T extends unknown[]>(...arrays: [K in keyof T]: ReadonlyArray<T[K]>): T[]

Builds N-tuples of elements from the given N arrays with matching indices, stopping when the smallest array's end is reached.

Examples

Example 1

import { zip } from "@std/collections/zip";
import { assertEquals } from "@std/assert/assert_equals";

const numbers = [1, 2, 3, 4];
const letters = ["a", "b", "c", "d"];
const pairs = zip(numbers, letters);

assertEquals(
  pairs,
  [
    [1, "a"],
    [2, "b"],
    [3, "c"],
    [4, "d"],
  ],
);

Type Parameters

T extends unknown[]

the type of the tuples produced by this function.

Parameters

...arrays: [K in keyof T]: ReadonlyArray<T[K]>

Return Type

Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@std/collections

Import symbol

import { zip } from "@std/collections";
or

Import directly with a jsr specifier

import { zip } from "jsr:@std/collections";