【发布时间】:2017-02-22 12:37:55
【问题描述】:
我有这样一段代码:
tg.router._routes.forEach(function(entry){
console.log(entry._commands[0]._textPattern)
});
因为在对象(entry._commands[0]._textPattern)里面是三项,console.log会被调用3次。
如何将“entry._commands[0]._textPattern”存储到变量(可以是数组)中,然后在匿名函数之外使用该变量?
我需要一个不同的变体,因为我不想稍后将 forEach 的输出一次全部传递给处理程序。
【问题讨论】:
标签: javascript foreach ecmascript-6