Lodash教程

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

\>node tester.js

输出

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