I have an array of URLs that i need to find the redirects for. I have been using XMLHttpRequest / xhr.responseURL to do so. When I print the results to the console, the redirected URLs display as expected. However, when I try to save those redirected URLs to an array, the array remains empty. How can I save them to the array?
Updated with code
var imageDestinations = [];
function imageDestinationGrabber(imageSource) {
var xhr = new XMLHttpRequest();
xhr.open('GET', imageSource, true);
xhr.onload = function() {
imageDestinations.push(xhr.responseURL).trim());
console.log((xhr.responseURL).trim());
};
xhr.send(null);
}
The console log works, but the array remains empty.