Lodash tap method
语法
_.tap(value, interceptor)
This method invokes interceptor and returns value. The interceptor is invoked with one argument; (value). The purpose of this method is to "tap into" a method chain sequence in order to modify intermediate results.
参数
value (*) − The value to provide to interceptor.
interceptor (Function) − The function to invoke.
输出
(*) − Returns value.
实例
var _ = require('lodash');
var values = [1, 2, 3];
var result = _(values)
.tap(function(array) {
array.pop();
})
.reverse()
.value();
console.log(result);
Save the above program in
tester.js. Run the following command to execute this program.
Command
输出