Click here to Skip to main content
15,348,829 members
Home / Discussions / JavaScript
   

JavaScript

 
AnswerRe: Loops, someone to help me Pin
Richard MacCutchan12-Apr-22 21:16
mveRichard MacCutchan12-Apr-22 21:16 
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 
Hello guys - can someone give me some advice on what I am doing wrong here?

I found out very tricky asynchronous functions in JS where "await" seems not to always mean to wait. I believe there should be similar behavior in JS but it doesn't work as expected - can someone please tell me how to achieve the goal? Let me share part of the code with a little explanation

translatedInUI.forEach(async (language) => {
     const actualLanguageCode = language.code;
     const actualLanguage = await file.getLanguage(language.code);
     const updatesForActual = []; // string array of keys to be updated
     const addToActual = []; // string array of keys to be added
     const removeFromActual = []; // string array of keys to be removed

     // add updates from changes in English
     updatesForActual.push(changesInEnglish);
     // find missing keys in actual language
     english.forEach((line) => {
       let key = line.key;
       if (!actualLanguage.find((element) => element.key == key)) {
         // console.log("key not found: " + key);
         addToActual.push(key);
       }
     });
     // find keys to remove in actual language
     actualLanguage.forEach((line) => {
       let key = line.key;
       if (!english.find((element) => element.key == key)) {
         console.log("key was removed: " + key);
         removeFromActual.push(key);
       }
     });
     // we should have collected all changes for actual language
     toAdd.push({ language: actualLanguageCode, addToActual });
     toRemove.push({ language: actualLanguageCode, removeFromActual });
     toUpdate.push({ language: actualLanguageCode, updatesForActual });
     console.log(toAdd);
   });
   // we should have collected list of changes:

   console.log("to add:" + toAdd);
   console.log(toRemove);
   console.log(toUpdate);


in this code console.log after the loop is displayed with empty variables first - the one at the end of each loops are displayed correctly while the one after loop goes out as an empty array

Thank you very much for any kind of advice
AnswerRe: Async call inside loop finishes later than loop itself Pin
Richard Deeming3-Apr-22 21:33
mveRichard Deeming3-Apr-22 21:33 
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 

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.