VOOZH about

URL: https://www.geeksforgeeks.org/javascript/underscore-js-_-invert-function/

⇱ Underscore.js _.invert() Function - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Underscore.js _.invert() Function

Last Updated : 12 Jul, 2025

Underscore.js_.invert() function is used to return the copy of an object where the object key is converted into value and object value is converted into the key. It means the [key, value] of the object is reversed.

Syntax:

_.invert( object );

Parameters:

  • object: It contains the object element that holds the elements of key and value pair.

Return Value:

It returns the [key, value] of an object in reverse [value, key] order.

Example 1: The below code will explain the implementation of the _.invert() function in underscore.js.

Output:

👁 Image

Example 2: The below code example is another implementation of the _.invert() function.

Output:

👁 Image
Comment