Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/ayonli_jsext/object/index.ts>invert

A JavaScript extension package for building strong and modern applications.
Latest
function invert
import { invert } from "https://deno.land/x/ayonli_jsext@v0.9.72/object/index.ts";

Composes a new record with all keys and values inverted.

This function is effectively as Object.fromEntries(Object.entries(record).map(([key, value]) => [value, key])).

Examples

Example 1

import { invert } from "@ayonli/jsext/object";

const obj = { foo: "Hello", bar: "World" };
const result = invert(obj);

console.log(result); // { Hello: "foo", World: "bar" }

Type Parameters

T extends Record<PropertyKey, PropertyKey>

Parameters

record: Readonly<T>

Returns

[P in keyof Tin keyof T[P]]: P