【发布时间】:2019-10-19 16:47:04
【问题描述】:
我在 https://www.googleapis.com/books/v1/volumes?q=wiedzmin 上使用 fetch。如果您转到此链接,您会看到它不是第 9 个对象中的任何 volumeInfo.authors(从第 545 行到第 602 行)。
它给了我一个错误:
Uncaught (in promise) TypeError: Cannot read property 'join' of undefined
我想做一个类似“如果有错误返回“No value found”的逻辑,代码执行会更进一步。
我的一段代码:
fetch("https://www.googleapis.com/books/v1/volumes?q=wiedzmin")
.then(resp => resp.json())
.then(x => {
console.log('AUTHORS: ')
for(let i=0; i <= x.items.length - 1; i++){
console.log(x.items[i].volumeInfo.authors.join(', '))
}
})
【问题讨论】:
标签: javascript object promise fetch