arrays - JSON to String Javascript -



arrays - JSON to String Javascript -

this question has reply here:

how homecoming response asynchronous call? 11 answers

the 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

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -