Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Lodash _.chain() Method

  • Last Updated : 16 Sep, 2020

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

Syntax:

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

_.chain(value)

Parameter: This method accept a single a parameter as mentioned above and described below:

  • value: This parameter holds the value to wrap.

Return value: This method returns the wrapped value.



Below example illustrate the Lodash _.chain() method in JavaScript:

Example 1:

Javascript




const _ = require('lodash'); 
  
var person = [
  { 'user': 'Tommy''income': 2600 },
  { 'user': 'Asmita',    'income': 2400 },
  { 'user': 'Hiyan', 'income': 2200 }
];
   
var 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:

Javascript




const _ = require('lodash'); 
  
var users = [
  { 'user': 'Tommy''age': 23 },
  { 'user': 'Asmita',    'age': 24 },
  { 'user': 'Hiyan', 'age': 22 }
];
   
var 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/




My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!