Skip to main content
Module

std/collections/zip.ts>zip

Deno standard library
Go to Latest
function zip
import { zip } from "https://deno.land/std@0.102.0/collections/zip.ts";

Builds 2-tuples of elements from the given array with matching indices, stopping when the smaller array's end is reached

Example:

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

console.assert(pairs === [
    [ 1, 'a' ],
    [ 2, 'b' ],
    [ 3, 'c' ],
    [ 4, 'd' ],
])

Parameters

array: Array<T>
withArray: Array<U>

Returns

Array<[T, U]>