我觉得这里缺少一些简单的东西。以我的代码为例:
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
我不明白为什么我可以最后在控制台中输出Array,但是.join()
为我返回了一个空字符串?