arrays - JSON to String Javascript -
arrays - JSON to String Javascript -
this question has reply here:
how homecoming response asynchronous call? 11 answersthe code below not seem able concatenate json result string, have thought why?
function wordcloud(filename) { var file = filename; var text = " "; $.getjson(file, function(data) { $.each(data, function(key, val) { text = text.concat(val.tostring()); }); }); console.log(text); }
thanks
it execute fine, have add together console.log
within statement because otherwise, getjson code runs asynchronously , in meantime when command reaches console.log statement, text
yet empty. have modify code in next way:
$.getjson(file, function(data) { $.each(data, function(key, val) { text = text.concat(val.tostring()); }); console.log(text); });
javascript arrays json string
Comments
Post a Comment