Last Updated : 20 Oct, 2023
Lodash _.chain() method is used to wrap the value with explicit method chain sequences enabled.
Syntax:_.chain(value);Parameter:
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/
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4