Click here to Skip to main content
15,510,802 members
Home / Discussions / JavaScript
   

JavaScript

 
QuestionReact date formatting Pin
Simon_Whale7-Apr-22 4:25
professionalSimon_Whale7-Apr-22 4:25 
AnswerRe: React date formatting Pin
Peter_in_27807-Apr-22 4:34
professionalPeter_in_27807-Apr-22 4:34 
AnswerRe: React date formatting Pin
Richard Deeming7-Apr-22 5:01
mveRichard Deeming7-Apr-22 5:01 
AnswerRe: React date formatting Pin
Jeremy Falcon26-Oct-22 13:01
professionalJeremy Falcon26-Oct-22 13:01 
Questionjava project Pin
Turki F773-Apr-22 16:30
Turki F773-Apr-22 16:30 
AnswerRe: java project Pin
Richard Deeming3-Apr-22 22:26
mveRichard Deeming3-Apr-22 22:26 
QuestionAsync call inside loop finishes later than loop itself Pin
Bohuslav Parenica2-Apr-22 1:51
Bohuslav Parenica2-Apr-22 1:51 
AnswerRe: Async call inside loop finishes later than loop itself Pin
Richard Deeming3-Apr-22 22:33
mveRichard Deeming3-Apr-22 22:33 
You are iterating over the translatedInUI array and starting an asynchronous task for each item. You never await those tasks, so the following code will execute before the tasks have finished.

Use a combination of Array.map[^] and Promise.all[^] to wait for the tasks to complete before trying to use the variables they're updating.
JavaScript
// Convert the source array to an array of Promise objects:
const tasks = translatedInUI.map(async (language) => {
    ...
});

// Wait for all of the promises to complete:
await Promise.all(tasks);

console.log("to add:", toAdd);
console.log("to remove:", toRemove);
console.log("to update:", toUpdate);
Obviously the outer function will also need to be marked as async for the await to work.

Using Promises - JavaScript | MDN[^]
async function - JavaScript | MDN[^]



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

AnswerRe: Async call inside loop finishes later than loop itself Pin
Jeremy Falcon26-Oct-22 13:14
professionalJeremy Falcon26-Oct-22 13:14 
QuestionTransforming Excel to Html (javascript) Pin
Member 1554681528-Mar-22 1:09
Member 1554681528-Mar-22 1:09 
GeneralMessage Closed Pin
23-Mar-22 20:02
Richardrussel23-Mar-22 20:02 
QuestionMessage Closed Pin
23-Mar-22 20:00
Richardrussel23-Mar-22 20:00 
QuestionFormulario js Pin
Member 155607559-Mar-22 8:18
Member 155607559-Mar-22 8:18 
AnswerRe: Formulario js Pin
RedDk9-Mar-22 8:33
RedDk9-Mar-22 8:33 
QuestionCreating a responsive menu Pin
Member 1554804125-Feb-22 5:58
Member 1554804125-Feb-22 5:58 
AnswerMessage Closed Pin
25-Feb-22 6:40
Member 1554804125-Feb-22 6:40 
AnswerMessage Closed Pin
25-Feb-22 6:41
Member 1554804125-Feb-22 6:41 
AnswerRe: Creating a responsive menu Pin
Member 1554804125-Feb-22 6:44
Member 1554804125-Feb-22 6:44 
AnswerRe: Creating a responsive menu Pin
Richard Deeming27-Feb-22 22:12
mveRichard Deeming27-Feb-22 22:12 
QuestionAdding auto expand functionality to collapsible script Pin
Member 1554681524-Feb-22 4:38
Member 1554681524-Feb-22 4:38 
AnswerRe: Adding auto expand functionality to collapsible script Pin
Member 1554681524-Feb-22 10:52
Member 1554681524-Feb-22 10:52 
QuestionProper decoding using Vanilla Javascript Pin
jkirkerx17-Feb-22 13:04
professionaljkirkerx17-Feb-22 13:04 
AnswerRe: Proper decoding using Vanilla Javascript Pin
Richard Deeming17-Feb-22 22:33
mveRichard Deeming17-Feb-22 22:33 
GeneralRe: Proper decoding using Vanilla Javascript Pin
jkirkerx18-Feb-22 7:49
professionaljkirkerx18-Feb-22 7:49 
GeneralRe: Proper decoding using Vanilla Javascript Pin
Richard Deeming24-Feb-22 1:21
mveRichard Deeming24-Feb-22 1:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.