Skip to content

unzipToArrays

Input an object obj, and return two arrays: one containing its keys and the other containing its values.

Added in v0.0.1

Usage

ts
import { unzipToArrays } from 'parsnip-kit'

const obj = {
 Alex: 16,
 Bob: 659,
 Carter: 155,
 Daniel: 825
}
unzipToArrays(obj)
// [['Alex', 'Bob', 'Carter', 'Daniel'], [16, 659, 155, 825]]

unzipToArrays(obj, (_, key) => key.toUpperCase(), (value) => value + '')
// [['ALEX', 'BOB', 'CARTER', 'DANIEL'], ['16', '659', '155', '825']]

API

Type Parameter

ArgTypeDescription
Textends objectType of original object

Arguments

ArgTypeOptionalDefaultDescription
objTfalseundefinedOriginal object
createKey(value: T[string & keyof T], key: string, obj: T) => anytrueundefinedTo create element of array of keys to be returned
createValue(value: T[string & keyof T], key: string, obj: T) => anytrueundefinedTo create element of array of values to be returned

Returns

Type
[string[], any[]]