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

x/ayonli_jsext/esm/object/index.js>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/esm/object/index.js";

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