@trashpanda001/helpers
    Preparing search index...

    Function mapObject

    • Given an object, map its entries (key, value) to a new key/value pair, and return a new object.

      If the mapping function generates duplicate keys, the latest entry wins.

      Type Parameters

      • T
      • S

      Parameters

      • object: Readonly<Record<string, T>>

        the object to map

      • keyValueFn: (entry: [string, T]) => [string, S]

        a function that takes an entry and returns a new entry

      Returns Record<string, S>

      a new object with the mapped entries

      import { mapObject } from "@trashpanda001/helpers/object"

      objectMap({ a: "alpha", b: "beta" }, ([k, v]) => [k, v.toUpperCase()])
      // { a: "ALPHA", b: "BETA" }
      objectMap({ a: "alpha", b: "beta" }, ([k, v]) => [v, k.toUpperCase()])
      // { alpha: "A", beta: "B" }