Aprendiendo un poco de JS y teniendo un problema en un proyecto en el que he estado trabajando. Tengo 2 funciones forEach en las que la segunda se basa en la primera para una variable. Quiero esperar a ambos para que el segundo solo se ejecute una vez que el primero forEach haya terminado. Esperaba algunos consejos (sé que esta no puede ser la forma más eficiente de hacerlo jajaja)
// test data to show structure const staff = [{ steamid: 'STEAM_0:1:1111111', server: 'testing'}]; const setStaffInfo = async function () { try { await staff.forEach(async (item) => { // this getSteamID64 is a fetch to convert steamID to steamID64 // this works fine const steamid64 = await util.getSteamID64(item.steamid); if (steamid64) item.steamid64 = steamid64; }); // PROBLEM! I believe this is running before the steamid64 is set in the prior forEach function await staff.forEach((el) => { if (el.server === "testing" && el.steamid64) { el.sits = 5; } }); } catch (err) { console.log(err); } };