I'm trying to achieve the URL tracking with below custom made script that extracts the json data that is in array and prints in console.log successfully
function redirecTrace(url){
var urltoprint = [];
  fetch("https://redirecttraceservice.com/api/v1/header-checker?initialURL="+url, {
  method: "POST"
})
.then(response => response.text()).then((response) => {
   var regex = new RegExp(/(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^"\s]{2,}) - Response 20[01]/);
   
   if(response.match(regex)){
      urltoprint = response.match(regex);
      console.log(encodeURIComponent(urltoprint[1]));
      return ("This is from return: " + urltoprint[1]);
   }else{
      console.log("Destination URL Not Found");
      return "Destination URL Not Found";
   }
});
}
So above code prints data in console.log but doesn't returns the data! It always says undefined?
 
     
    