それは動作しdocument.addEventListener("DOMContentLoaded", async () => {})
ますが、JQuery で動作させることに興味があります。
また、後で約束コールバックの外で変数が必要になるため、約束ではなく、Async/Await を使用したいと考えています。
let products = [];
$(document).ready(async function() { // Does not work with ASYNC
await getProducts(); // IF i dont use async await, products = empty
products.forEach(product => console.log(product))
})
const getProducts = () => {
// Ajax call to server
// products = ajaxResult; // asign variable to result
// returns Promise;
}