Skip to content

splitToArrays

Input an object obj, and return an array of plain objects formed from each field of the obj, split by the object, or composed of the results returned by the optional parameter createItem.

Added in v0.0.1

Usage

ts
import { splitToArrays } from 'parsnip-kit'

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

splitToArrays(obj, (value, key) => [key, value])
// [['Alex', 16], ['Bob', 659], ['Carter', 155], ['Daniel', 825]]

API

Type Parameter

ArgTypeDescription
Textends objectType of original object

Arguments

ArgTypeOptionalDefaultDescription
objobjectfalseundefinedOriginal object
createItem(value: T[string & keyof T], key: string, obj: T) => anytrueundefinedTo create element of array to be returned

Returns

Type
any[]