[英]Accessing attributes inside object
我正在我的 componentDidMount 中进行提取,如下所示
componentDidMount() {
fetch('https://cors-anywhere.herokuapp.com/http://api.plos.org/search?q=title:DNA', {
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Credentials": true,
}
})
.then(response => response.json())
.then((data)=>{
console.log(data);
});
}
我的控制台输出数据如下
{response: {…}}
response:
docs: (10) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
maxScore: 6.3768473
numFound: 5026
start: 0
__proto__: Object
__proto__: Object
我想在这里访问 docs 数组。 我试过console.log(data.docs);
但它返回一个未定义的。 我在这里做错了什么?
你应该试试 =>
console.log(data.response.docs);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.