Lodash教程

Lodash thru method

语法

_.thru(value, interceptor)
This method is like _.tap except that it returns the result of interceptor. The purpose of this method is to "pass thru" values replacing intermediate results in a method chain sequence.

参数

value (*) − The value to provide to interceptor. interceptor (Function) − The function to invoke.

输出

(*) − Returns the result of interceptor.

实例

var _ = require('lodash');  
var result = _('   abc   ')
   .chain()
   .trim()
   .thru(function(value) {
      return [value];
   })
   .value();
   
console.log(result);
Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

输出

[ 'abc' ]
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4