Lodash教程

Lodash chain method

语法

_.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.

参数

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

\>node tester.js

输出

Robert is 10
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4