Lodash chain method
语法
Creates a lodash wrapper instance that wraps value with explicit method chain sequences enabled. The result of such sequences must be unwrapped with _#value.
参数
value (*) − The value to wrap.
输出
(Object) − Returns the new lodash wrapper instance.
实例
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
输出