Skip to content

objectToPairs

输入对象obj,返回一个数组,由每个字段的键值对形成的数组组成数组,或由可选参数createItem返回组成。

Added in v0.0.1

Usage

ts
import { objectToPairs } from 'parsnip-kit'

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

objectToPairs(obj, (value, key) => ({ [key]: value }))
// [{ Alex: 16 }, { Bob: 659 }, { Carter: 155 }, { Daniel: 825 }]

API

Type Parameter

ArgTypeDescription
Textends object原对象的类型

Arguments

ArgTypeOptionalDefaultDescription
objTfalseundefined原对象
createItem(value: T[string & keyof T], key: string, obj: T) => anytrueundefined创建数组元素

Returns

Type
any[]