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?