- Lodash Tutorial
- Lodash - Home
- Lodash - Overview
- Lodash - Environment Setup
- Lodash - Array
- Lodash - Collection
- Lodash - Date
- Lodash - Function
- Lodash - Lang
- Lodash - Math
- Lodash - Number
- Lodash - Object
- Lodash - Seq
- Lodash - String
- Lodash - Util
- Lodash - Properties
- Lodash - Methods
- Lodash Useful Resources
- Lodash - Quick Guide
- Lodash - Useful Resources
- Lodash - Discussion
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