To use the invert()
function from the Underscore library in TypeScript, you first need to install the library via npm:
index.ts23 chars2 lines
Then, you can import it in your TypeScript file like this:
index.ts33 chars2 lines
Assuming you have an object with key-value pairs and want to swap the keys and values, you can use the invert()
function like this:
index.ts215 chars4 lines
This will create a new object with the values of the original object as keys, and the keys of the original object as values. The invert()
function works with both string and number values.
gistlibby LogSnag