Skip to content

mapEntries

Map the keys and values of an object

127 bytes

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 _
_
.
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<...>
export mapEntries

Map over all the keys to create a new object.

@seehttps://radashi.js.org/reference/object/mapEntries

@example

const a = { a: 1, b: 2, c: 3 }
mapEntries(a, (key, value) => [value, key])
// => { 1: 'a', 2: 'b', 3: 'c' }

@version12.1.0

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' }