mapEntries
Map the keys and values of an object
127 bytes
since v12.1.0
Usage
Iterates the entries of an object, calling the given toEntry callback function
to generate new entries. It’s a _.mapValues and _.mapKeys
in one. The toEntry callback function should return an array with
two items [key, value] (a.k.a the new entry).
import * as import _
_ from 'radashi'
const const ra: { name: string; power: string; rank: number; culture: string;}
ra = { name: string
name: 'Ra', power: string
power: 'sun', rank: number
rank: 100, culture: string
culture: 'egypt',}
import _
_.function mapEntries<"name" | "power" | "rank" | "culture", string | number, string, string>(obj: Record<"name" | "power" | "rank" | "culture", string | number>, toEntry: (key: "name" | "power" | "rank" | "culture", value: string | number) => [...]): Record<...>
Map over all the keys to create a new object.
mapEntries(const ra: { name: string; power: string; rank: number; culture: string;}
ra, (key: "name" | "power" | "rank" | "culture"
key, value: string | number
value) => [key: "name" | "power" | "rank" | "culture"
key.String.toUpperCase(): string
Converts all the alphabetic characters in a string to uppercase.
toUpperCase(), `${value: string | number
value}`]) // => { NAME: 'Ra', POWER: 'sun', RANK: '100', CULTURE: 'egypt' }