$('#search-form').submit(async () => {
var urls = await FetchUrls();
console.log(urls);
});
function FetchUrls() {
var array = [];
return new Promise((resolve, reject) => {
$.getJSON("list.json", (json) => {
$.each(json, (index, field) => {
categories.forEach((item) => {
if (item === field.major) {
array = array.concat(field.x);
array = array.concat(field.y);
}
});
});
});
resolve(array);
});
}
Why that doesn't wait for FetchUrls return?
I use await keyword for that.
It logs urls before urls get filled.