1

I feel like I am missing something simple here. Take my code for example:

  var names = [];
  var urlname = [];
  names = JSON.parse(localStorage.getItem('saved-names'));

     names.forEach(function(key) {
        jQuery.getJSON(
        "https://webpro.com/api/v5/info.php?name="+key,
        function(data) { 
            jQuery.each(data, function (i, val) {         
                urlname.push("||1 " + encodeURIComponent(val.name));      
            });               
        });                  
    }); //End forEach name Loop

    console.log(urlname); //This outputs the array with all the names
    console.log("String: " + urlname.join("")); //This is empty

I can't understand why I can output the Array in the console at the end but .join() is returning an empty string for me?

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
GenesisBits
  • 364
  • 2
  • 23
  • First duplicate is why the array is empty when you join it, second duplicate is why the console updates to show the data after the array is modified. – Quentin Jun 19 '19 at 14:44

0 Answers0