var list = [];
$.getJSON(\"json.js\", function(data) {
$.each(data, function(i, item) {
console.log(item.text);
list.push(item.text);
});
});
con
Since $.getJSON
is async, I think your console.log(list.length);
code is firing before your array has been populated. To correct this put your console.log
statement inside your callback:
var list = new Array();
$.getJSON("json.js", function(data) {
$.each(data, function(i, item) {
console.log(item.text);
list.push(item.text);
});
console.log(list.length);
});