> For the complete documentation index, see [llms.txt](https://heihei12305.gitbook.io/my-underscore/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://heihei12305.gitbook.io/my-underscore/untitled/yong-yu-tiao-shi-de-tap.md).

# 用于调试的tap()

假设你在遍历一个来自服务器的数组,并发现数据错了.因此你想调试一下,看看你数组里究竟包含了什么.\
&#x20;不要使用命令式的方法,要用函数式的方法.我们需要一种调试方式.

```
_.tap = (value)=>
        (fn)=>{
                typeof(fn) === 'function' && fn(value);
                console.log(value);
        }
```

我们可以这样用:

```
_.forEach([1,2,3],(a)=>
    _.tap(a)(()=>{
        console.log(a);//1 1 2 2 3 3
    })
)
```
