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
输出