Click here to Skip to main content
15,350,704 members
Home / Discussions / JavaScript
   

JavaScript

 
AnswerRe: Loops, someone to help me Pin
Member 1562749529-May-22 21:29
MemberMember 1562749529-May-22 21:29 
QuestionReact date formatting Pin
Simon_Whale7-Apr-22 3:25
professionalSimon_Whale7-Apr-22 3:25 
AnswerRe: React date formatting Pin
Peter_in_27807-Apr-22 3:34
professionalPeter_in_27807-Apr-22 3:34 
AnswerRe: React date formatting Pin
Richard Deeming7-Apr-22 4:01
mveRichard Deeming7-Apr-22 4:01 
Questionjava project Pin
Turki F773-Apr-22 15:30
MemberTurki F773-Apr-22 15:30 
AnswerRe: java project Pin
Richard Deeming3-Apr-22 21:26
mveRichard Deeming3-Apr-22 21:26 
QuestionAsync call inside loop finishes later than loop itself Pin
Bohuslav Parenica2-Apr-22 0:51
MemberBohuslav Parenica2-Apr-22 0:51 
AnswerRe: Async call inside loop finishes later than loop itself Pin
Richard Deeming3-Apr-22 21:33
mveRichard Deeming3-Apr-22 21: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

QuestionTransforming Excel to Html (javascript) Pin
Member 1554681528-Mar-22 0:09
MemberMember 1554681528-Mar-22 0:09 
GeneralMessage Closed Pin
23-Mar-22 19:02
MemberRichardrussel23-Mar-22 19:02 
QuestionMessage Closed Pin
23-Mar-22 19:00
MemberRichardrussel23-Mar-22 19:00 
QuestionFormulario js Pin
Member 155607559-Mar-22 7:18
MemberMember 155607559-Mar-22 7:18 
AnswerRe: Formulario js Pin
RedDk9-Mar-22 7:33
MemberRedDk9-Mar-22 7:33 
QuestionCreating a responsive menu Pin
Member 1554804125-Feb-22 4:58
MemberMember 1554804125-Feb-22 4:58 
AnswerMessage Closed Pin
25-Feb-22 5:40
MemberMember 1554804125-Feb-22 5:40 
AnswerMessage Closed Pin
25-Feb-22 5:41
MemberMember 1554804125-Feb-22 5:41 
AnswerRe: Creating a responsive menu Pin
Member 1554804125-Feb-22 5:44
MemberMember 1554804125-Feb-22 5:44 
AnswerRe: Creating a responsive menu Pin
Richard Deeming27-Feb-22 21:12
mveRichard Deeming27-Feb-22 21:12 
QuestionAdding auto expand functionality to collapsible script Pin
Member 1554681524-Feb-22 3:38
MemberMember 1554681524-Feb-22 3:38 
AnswerRe: Adding auto expand functionality to collapsible script Pin
Member 1554681524-Feb-22 9:52
MemberMember 1554681524-Feb-22 9:52 
QuestionProper decoding using Vanilla Javascript Pin
jkirkerx17-Feb-22 12:04
professionaljkirkerx17-Feb-22 12:04 
AnswerRe: Proper decoding using Vanilla Javascript Pin
Richard Deeming17-Feb-22 21:33
mveRichard Deeming17-Feb-22 21:33 
GeneralRe: Proper decoding using Vanilla Javascript Pin
jkirkerx18-Feb-22 6:49
professionaljkirkerx18-Feb-22 6:49 
GeneralRe: Proper decoding using Vanilla Javascript Pin
Richard Deeming24-Feb-22 0:21
mveRichard Deeming24-Feb-22 0:21 
GeneralRe: Proper decoding using Vanilla Javascript Pin
jkirkerx24-Feb-22 5:37
professionaljkirkerx24-Feb-22 5:37 

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.