Unzip an array of arrays

Regroup the n-th item of every array into the n-th output array.

JavaScript Version 1.0.0 · MIT · .md

unzip-an-array-of-arrays.js
function unzip(arrays) { return Array.from({ length: Math.max(0, ...arrays.map(array => array.length)) }, (_, i) => arrays.filter(array => i < array.length).map(array => array[i])); }

Input & expected output

Input

[
  [
    "[email protected]",
    "delivered"
  ],
  [
    "[email protected]",
    "deferred"
  ]
]

Expected output

[
  [
    "[email protected]",
    "[email protected]"
  ],
  [
    "delivered",
    "deferred"
  ]
]

The edge case

Input

[]

Expected output

[]

Know the limits

  • Shorter arrays simply contribute fewer items.
  • The inverse of Zip multiple arrays.

The function above is the implementation used by the lab. The lab validates JSON types and caps size before execution; include equivalent validation when accepting untrusted input in your application.

Source & maintenance

Based on Unzip an array of arrays from the original 1loc collection by Nguyen Huu Phuoc. Copyright (c) 2020 phuoc-ng. MIT licensed.

Builds each column with filter and map instead of pushing into accumulators; handles an empty input. Original MDX retained as inert source evidence.

Maintained by Oveyon. Source commit: 14b481cf60df. Read the license.

Local fixture scope · Node.js 22.23.2 · reviewed October 28, 2026. No external service is required.

Keep exploring

Type two or more characters. Try “duplicate”, “webhook” or “retry”.