Skip to main content
Module

std/collections/unzip.ts>unzip

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

Builds two separate arrays from the given array of 2-tuples, with the first returned array holding all first tuple elements and the second one holding all the second elements

Example:

const parents = [
    [ 'Maria', 'Jeff' ],
    [ 'Anna', 'Kim' ],
    [ 'John', 'Leroy' ],
]
const [ moms, dads ] = unzip(parents)

console.assert(moms === [ 'Maria', 'Anna', 'John' ])
console.assert(moms === [ 'Jeff', 'Kim', 'Leroy' ])

Parameters

pairs: Array<[T, U]>

Returns

[Array<T>, Array<U>]