I'm trying to create a bookmarklet that tracks all the links on a page, check how the server responds and return the http requests.
The problem I'm encountering is that I'm not achieving get data from array. This is my code:
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 ¿?¿?
Does anyone know how I can access to the data in the array? I don't know what else I can do ...