我有这样一段代码:
tg.router._routes.forEach(function(entry){
console.log(entry._commands[0]._textPattern)
});因为在对象(entry._commands._textPattern)中有三个项,所以console.log将被调用三次。
我如何将"entry._commands._textPattern“存储到变量(可以是数组)中,然后在匿名函数之外使用该变量?
我需要一个不同的变体,因为我以后不会将forEach的输出一次传递给一个处理程序。
发布于 2017-02-22 12:39:21
您可以尝试使用map
const something = tg.router._routes.map(entry => entry._commands[0]._textPattern);https://stackoverflow.com/questions/42391724
复制相似问题