Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

std/collections/mod.ts>unzip

Deno standard library
Go to Latest
The Standard Library has been moved to JSR. See the blog post for details.
function unzip
import { unzip } from "https://deno.land/std@0.158.0/collections/mod.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:

import { unzip } from "https://deno.land/std@0.158.0/collections/unzip.ts";
import { assertEquals } from "https://deno.land/std@0.158.0/testing/asserts.ts";

const parents = [
    [ 'Maria', 'Jeff' ],
    [ 'Anna', 'Kim' ],
    [ 'John', 'Leroy' ],
] as [string, string][];

const [ moms, dads ] = unzip(parents);

assertEquals(moms, [ 'Maria', 'Anna', 'John' ]);
assertEquals(dads, [ 'Jeff', 'Kim', 'Leroy' ]);

Parameters

pairs: readonly [T, U][]

Returns

[T[], U[]]