Skip to content

forEachFields

Static Badge

A function that takes an object obj and an iterator function, iterates over each field of the object, and executes the iterator for each field's value.

Added in v0.0.1

Usage

ts
import { forEachFields } from 'parsnip-kit'

const user = { name: 'John', age: 30 }
forEachFields(user, (value, key, obj) => {
  console.log(`Key: ${key}, Value: ${value}`)
})
// Key: name, Value: John
// Key: age, Value: 30

API

Type Parameter

ArgTypeDescription
Textends objectObject type

Arguments

ArgTypeOptionalDefaultDescription
objTfalseundefinedObject to iterate
iterator(value: any, key: string, object: T) => anyfalseundefinedIterator function

Returns

Type
void