Lodash - chain method



Syntax

_.chain(value)

Creates a lodash wrapper instance that wraps value with explicit method chain sequences enabled. The result of such sequences must be unwrapped with _#value.

Arguments

  • value (*) − The value to wrap.

Output

  • (Object) − Returns the new lodash wrapper instance.

Example

var _ = require('lodash');
var users = [
   { 'user': 'Joe',   'age': 36 },
   { 'user': 'Julie',     'age': 40 },
   { 'user': 'Robert', 'age': 10 }
];

var youngest = _
   .chain(users)
   .sortBy('age')
   .map(function(o) {
      return o.user + ' is ' + o.age;
   })
   .head()
   .value();

console.log(youngest);

Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

Output

Robert is 10
lodash_seq.htm
Advertisements