QuickSnip LogoA light blue logo with a thunderbolt in bracketsQuickSnip

Zip Arrays

Combines two arrays by pairing corresponding elements from each array.

  • array
  • map

Install

npx shadcn@latest add https://quicksnip.dev/r/zip-arrays.json

This snippet is not verified yet. Review it before use, or help verify it.

Code

const zip = (arr1, arr2) => arr1.map((value, index) => [value, arr2[index]]);

Usage

const arr1 = ['a', 'b', 'c'];
const arr2 = [1, 2, 3];
console.log(zip(arr1, arr2)); // Output: [['a', 1], ['b', 2], ['c', 3]]