Monday, December 15, 2025
HomeLanguagesJavascriptLodash _.chain() Method

Lodash _.chain() Method

Lodash _.chain() method is used to wrap the value with explicit method chain sequences enabled. 

Syntax:

_.chain(value);

Parameter:

  • value parameter holds the value to wrap.

Return value:

This method returns the wrapped value.

Example 1: In this example, we have used the _.chain() method in which we have passed the ‘person’ object sorting them by ‘income’ and printing their values in the console.

Javascript




const _ = require('lodash');
 
let person = [
    { 'user': 'Tommy', 'income': 2600 },
    { 'user': 'Asmita', 'income': 2400 },
    { 'user': 'Hiyan', 'income': 2200 }
];
 
let Earcning = _
    .chain(person)
    .sortBy('income')
    .map(function (gfg) {
        return gfg.user + ' earn is ' + gfg.income;
    })
    .value();
console.log(Earcning)


Output:

[ 'Hiyan earn is 2200', 'Asmita earn is 2400', 'Tommy earn is 2600' ]

Example 2: In this example, we have used the _.chain() method in which we have passed the ‘users’ object sorting them and printing their values in the console.

Javascript




const _ = require('lodash');
 
let users = [
    { 'user': 'Tommy', 'age': 23 },
    { 'user': 'Asmita', 'age': 24 },
    { 'user': 'Hiyan', 'age': 22 }
];
 
let youngest = _
    .chain(users)
    .sortBy('age')
    .map(function (o) {
        return o.user + ' is ' + o.age;
    })
    .tail()
    .value();
console.log(youngest)


Output:

[ 'Tommy is 23', 'Asmita is 24' ]

Reference: https://docs-lodash.com/v4/chain/

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen 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!
RELATED ARTICLES

2 COMMENTS

Most Popular

Dominic
32448 POSTS0 COMMENTS
Milvus
105 POSTS0 COMMENTS
Nango Kala
6817 POSTS0 COMMENTS
Nicole Veronica
11954 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12031 POSTS0 COMMENTS
Shaida Kate Naidoo
6955 POSTS0 COMMENTS
Ted Musemwa
7202 POSTS0 COMMENTS
Thapelo Manthata
6899 POSTS0 COMMENTS
Umr Jansen
6884 POSTS0 COMMENTS