无法返回数组外部功能

时间:2017-05-03 19:55:07

标签: javascript angularjs arrays node.js

我有一个功能

function gotData(data){
    result = data.val() 
    const urls = Object.keys(result)
                 .filter(key => result[key].last_res > 5)
                 .map(key => ({url: 's/price/' + result[key].url_site + '/'}))
}
console.log(urls)

但我不能将console.log(urls)显示为错误

ReferenceError: urls is not defined

如何退回网址?

1 个答案:

答案 0 :(得分:0)

你的函数gotData应该返回urls,

function gotData(data){
    result = data.val() 
    return urls = Object.keys(result)
                 .filter(key => result[key].last_res > 5)
                 .map(key => ({url: 's/price/' + result[key].url_site + '/'}))
}
 console.log(gotData(yourdata));