Thursday, November 20, 2025
HomeLanguagesJavascriptLodash _.identity() Method

Lodash _.identity() Method

Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc. The _.identity method returns the first argument it receives.

Syntax:

_.identity(value)

Parameters: This method accepts one parameter as mentioned above and described below:

  • value: It can be any value.

Returns: Returns the first argument it receives.

Example 1:




// Requiring the lodash library  
const _ = require("lodash");        
  
// Use of _.identity() method   
var user = [
  { 'name': 'XXXX', 'age': 36, 'active': true },
  { 'name': 'YYYY',   'age': 40, 'active': false }
];
  
let gfg = _.identity(user);
  
// Printing the output  
console.log(gfg);


Note: Here, const _ = require(‘lodash’) is used to import the lodash library in the file.

Output:

[Object {active: true, age: 36, name: "XXXX"}, Object {active: false, age: 40, name: "YYYY"}]

Example 2:




// Requiring the lodash library  
const _ = require("lodash");        
  
// Use of _.identity() method   
var company = { 'name': 'neveropen' };
  
let gfg = _.identity(company) === company;
  
// Printing the output  
console.log(gfg);


Note: Here, const _ = require(‘lodash’) is used to import the lodash library in the file.

Output:

true
RELATED ARTICLES

Most Popular

Dominic
32404 POSTS0 COMMENTS
Milvus
97 POSTS0 COMMENTS
Nango Kala
6776 POSTS0 COMMENTS
Nicole Veronica
11924 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11994 POSTS0 COMMENTS
Shaida Kate Naidoo
6904 POSTS0 COMMENTS
Ted Musemwa
7160 POSTS0 COMMENTS
Thapelo Manthata
6859 POSTS0 COMMENTS
Umr Jansen
6846 POSTS0 COMMENTS