Zip multiple arrays

Pair the n-th items of several arrays.

JavaScript Version 1.0.0 · MIT · .md

zip-multiple-arrays.js
function zip(arrays) { return Array.from({ length: Math.max(0, ...arrays.map(array => array.length)) }, (_, i) => arrays.map(array => array[i] ?? null)); }

Input & expected output

Input

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

Expected output

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

The edge case

Input

[
  [
    "a",
    "b"
  ],
  [
    1
  ]
]

Expected output

[
  [
    "a",
    1
  ],
  [
    "b",
    null
  ]
]

Know the limits

  • Missing items become null (undefined in the original) so the result is JSON-representable.
  • The original took arrays as separate arguments.

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 Zip multiple arrays from the original 1loc collection by Nguyen Huu Phuoc. Copyright (c) 2020 phuoc-ng. MIT licensed.

Takes one array of arrays; missing items become null so the result is JSON-representable. 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”.