【发布时间】:2021-06-27 06:12:57
【问题描述】:
这是函数:
export const getSafestCountriesNames = async() => {
try{
const names = await getCountriesData();
names.forEach((country) => {
const {score} = country.advisory;
if(score == 0){
const liEl = createDOMElement('li', {className: 'name'});
liEl.innerHTML = `${country.name}`;
return liEl;
}
});
}
// …
}
当我在这里调用它时,我得到undefined:
async function func(){
const names = await getSafestCountriesNames();
console.log(names);
}
func();
【问题讨论】:
-
func 的结果应该是未定义的,它不返回任何东西。你的意思是 func 里面的控制台日志打印 undefined 吗?
标签: javascript async-await promise