es-toolkit/docs/reference/array/unzip.md
seunghee 208cb09c8b
feat(unzip): add unzip (#130)
* feat: unzip function

* test: unzip test

* chore: unzip bench

* docs: unzip

* docs: unzip

* docs: unzip

* Update src/array/unzip.ts

* Update docs/ko/reference/array/unzip.md

* Update src/array/unzip.ts

* Update docs/reference/array/unzip.md

* Update unzip.md

---------

Co-authored-by: Sojin Park <raon0211@gmail.com>
Co-authored-by: Sojin Park <raon0211@toss.im>
2024-07-08 21:35:45 +09:00

623 B

unzip

Gathers elements in the same position in an internal array from a grouped array of elements and returns them as a new array.

Signature

type Unzip<K extends unknown[]> = { [I in keyof K]: Array<K[I]> };
function unzip<T extends unknown[]>(zipped: Array<[...T]>): Unzip<T>;

Parameters

  • zipped (Array<[...T]>): An array of grouped elements.

Returns

(Unzip<T>): An new array created by collecting elements at the same position in an internal array.

Example

unzip([
  ['a', true, 1],
  ['b', false, 2],
]);
// return: [['a', 'b'], [true, false], [1, 2]]