【发布时间】:2020-06-29 15:26:15
【问题描述】:
我正在尝试创建一个小书签来跟踪页面上的所有链接,检查服务器如何响应并返回 http 请求。
我遇到的问题是我没有实现从数组中获取数据。 这是我的代码:
let a = document.getElementsByTagName('a');
let code = [];
for(let i=0; i<a.length; i++) {
let myRequest = a[i].href;
let x = fetch(myRequest).then(function(response) {
return response.status;
})
x.then(function(result) {
code.push((result));
})
}
console.log(code); // [200, 200, ....]
console.log(Array.isArray(code)); // true
let codeOne = code[0];
console.log(codeOne); // undefined ¿?¿?
有谁知道我如何访问数组中的数据? 我不知道我还能做什么......
【问题讨论】:
标签: javascript arrays promise fetch fetch-api