Tweakr
    Preparing search index...

    Function invert

    • Inverts the keys and values of an object.

      Converts all values to strings and uses them as keys in the resulting object.

      Parameters

      • obj: Record<string, string | number>

        The object whose keys and values will be inverted.

      Returns Record<string, string>

      A new object with keys and values swapped.

      const obj = { a: "1", b: "2" };
      const inverted = invert(obj);
      console.log(inverted); // { "1": "a", "2": "b" }

      1.1.0