The Wayback Machine - https://web.archive.org/web/20240118171345/https://www.geeksforgeeks.org/lodash-_-identity-method/
Open In App
Related Articles

Lodash _.identity() Method

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

Lodash _.identity method returns the first argument it receives.

Syntax:

_.identity(value);

Parameters:

  • value: It can be any value.

Return Value:

Returns the first argument it receives.

Example 1: In this example, it is returning the first parameter because of the lodash _.identity() method.

javascript




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


Output:

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

Example 2: In this example, it is returning true as the first parameter of the lodash _.identity() method returning the same element as it stored in a company variable.

javascript




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


Output:

true
Learn to code easily with our course Coding for Everyone. This course is accessible and designed for everyone, even if you're new to coding. Start today and join millions on a journey to improve your skills!

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 27 Oct, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials