我有一个JS函数,该函数应采用Github用户名并将其应用于一组回购URL。我正在尝试使用async-await来获取数据(如果找到)。我能够解决Promise,但无法访问Native Promise。
这是我在诺言解决后在控制台中看到的:
Promise {[[PromiseStatus]]: "pending",[[PromiseValue]]: undefined}
__proto__: Promise
[[PromiseStatus]]: "resolved"
[[PromiseValue]]: Array(38)
我希望能够遍历返回的数组的值。就我而言,返回数组中将有38个对象。
这是我的异步功能:
async function getUserExercises(githubName) {
const exerciseURLs = [
`https://api.github.com/repos/${githubName}/repo-name/contents/`
// `https://api.github.com/repos/${githubName}/repo-name/contents/css/`,
// `https://api.github.com/repos/${githubName}/repo-name/contents/js/`,
// `https://api.github.com/repos/${githubName}/repo-name/contents/es6`,
]
const exerciseRepos = exerciseURLs.map(
async url => {
let response = await fetch(url)
if(response.status == 200) {
return await response.json()
}else{
// Error message function that displays error on Page
showErrorMsg(response.statusText)
}
}
)
console.log(exerciseRepos)
}