Тёмный

Asynchronous Behavior in Loops: forEach() vs for...of - JavaScript 

willjw3
Подписаться 2,1 тыс.
Просмотров 14 тыс.
50% 1

Опубликовано:

 

22 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 43   
@MiSt3300
@MiSt3300 3 года назад
Looks like you solved the thing I've been looking for a whole fortnight.... It was my worst programming pain EVER. Thanks so much for this.
@aspirinemaga
@aspirinemaga 2 года назад
more pain to go buddy
@satindersingh9671
@satindersingh9671 4 года назад
I guess for...of loop worked because you use async on the parent function, of which console.log(newArr) was part of or was present within that async function, which is not happening in case of a forEach loop. It is not an inherent behavior of for...of loop but the way you wrote code.
@ibadshaikh2215
@ibadshaikh2215 3 года назад
Dear, you saved my day!!! I was hanging in this error the entire day.
@eduardokiriakos6255
@eduardokiriakos6255 3 года назад
Thank you SO MUCH! I have breaking my head around this problem for 2 days until now!
@nicolopezcesan6006
@nicolopezcesan6006 4 года назад
I've wasted all day hanging around this, even though I had the correct async await syntax. It was finally because of the fucking foreach. Thank you man!
@untildawn5714
@untildawn5714 4 года назад
Thank you @Will Ward! My server uses python asyncio and websockets and it has a loop what is collecting the "online" status from the column of "usernames" from the database , push to frontend in json format, similar with your initial array. Every time when the front end got an update it had not updated the list just appended, but the console log worked fine. After I learned from you how to use the foreach properly with asynchronous updated. my "sidebar list" with " usernames" works as expected. Keep up the good work!
@Howleyy13
@Howleyy13 3 года назад
Just amazing... thank you even 2 years later
@charlydt88
@charlydt88 4 года назад
Thank you man! I've been looking to sort this problem for quite a while, I didnt realize the forEach was the problem
@subhamroy7715
@subhamroy7715 Год назад
Great man nicely explained, was struck whole day & night deadline task
@fridayokorie2642
@fridayokorie2642 3 года назад
been on this one for almost 2 weeks....thanks sir. Keep up the good work.
@nikunjjoshi93
@nikunjjoshi93 3 года назад
Dude, it's working I try for one day solving this error whenever I send response it went empty...now it's working fine..thank you so much.......
@adrianalfonsocanojaramillo4078
@adrianalfonsocanojaramillo4078 4 года назад
Thank you very much! This works amazing, you just saved my day. Great job!
@anshultiwari2704
@anshultiwari2704 4 года назад
Thankyou so much sir i had been struggling the whole day because of the forEach, if it wasn't you this problem would've taken a week .
@ismaelvarela9193
@ismaelvarela9193 Год назад
this is an ideal topic, you nailed it!
@AkashGupta-pc2cb
@AkashGupta-pc2cb Год назад
The solution I was looking for 😅. Thank you
@digvijayyamagekar4300
@digvijayyamagekar4300 3 года назад
that was a life saver man thank you very much
@sowmik.reborn
@sowmik.reborn 3 года назад
Great! But one thing that made the video annoying is not using *easy keyboard shortcuts* 😩
@adrianr6084
@adrianr6084 2 года назад
This was very useful. Thanks !
@paappan4124
@paappan4124 3 года назад
Please, keep making more videos. probably just me, watching using file-> save, kills.
@typingguru4088
@typingguru4088 3 года назад
Simple and to the point !! with love
@vinayarunkumar8259
@vinayarunkumar8259 2 года назад
Gold✨✨✨........wish I had found this before🙂
@martinm.8197
@martinm.8197 2 года назад
Thanks, that really helped!
@braxtonyoung
@braxtonyoung 3 года назад
You're a freaking legend! thanks!
@ruhan23
@ruhan23 2 года назад
I figured that out yesterday the whole day, i am here to find out "why" this happens
@shubhamverma1407
@shubhamverma1407 3 года назад
Thank you very much 🙂
@AmanYadav-wm9og
@AmanYadav-wm9og 2 года назад
Thank you so much it's been pain for me
@n.a.e.v
@n.a.e.v 3 года назад
does this apply to other array methods like filter, map and reduce?
@rafaelcosta8535
@rafaelcosta8535 3 года назад
Thank you!!
@stealthseeker18
@stealthseeker18 4 года назад
Damn! I like your teaching style man! You save my day. Problem solved! Thanks.... From subscribe to subscribed.
@bhaskarjha2736
@bhaskarjha2736 3 года назад
Thank you boss!
@digvijayyamagekar4300
@digvijayyamagekar4300 3 года назад
hey I have a question let's say all this code is inside an async function and I want to return the newArr (in your case you are logging it), Whenever I call my async function newArr should be returned instead of logging it how to do that?
@willjw3717
@willjw3717 3 года назад
Have you tried just returning it instead of logging it to the console?
@ChiNguyen-ft4yq
@ChiNguyen-ft4yq 4 года назад
Thank you so mush
@jadenbaker9754
@jadenbaker9754 2 года назад
I fucking love you
@arjay_2002
@arjay_2002 3 года назад
omg ty
@maciej12345678
@maciej12345678 2 года назад
this is not the same 5:50 make this with forEach :D with async on function not in loop !!!
@victorvondoom2350
@victorvondoom2350 2 года назад
am getting infinite loop while doing this , res.send()
@greendsnow
@greendsnow 2 года назад
I've been getting bald hair by hair in front of this stupid JS issue...
@jjcampis
@jjcampis 2 года назад
EXCELLENT! thank you so much! i was trying to get axios request in some order of an array an this is the solution :) ill leave my code here for anyone that is looking for the same: const members = [{"id":1,"name":"jhon"}] //this is an example async function get_from_axios(){ for (const member of members) { let response = await axios.get(axios.defaults.baseURL+'/url?query='+member.id) //return response await this.another(response.data);//must return a promise to wait another() } } async function another(data){ return new Promise((resolve)=>{ setTimeout(() => { resolve(console.log(data)); }, 1500); }) } if it didnt work is because i added the 'function' word because i pulled out from methods in vue and tryed to share with you :) im so glad for have find this video greetings from Argentina
@willjw3717
@willjw3717 2 года назад
Glad it helped!
Далее
Settling the Biggest Await Async Debate in .NET
14:47
Просмотров 145 тыс.
5 Tips for Writing BETTER For Loops in JavaScript
16:15
C# Async Await Mistakes | Part 1
10:19
Просмотров 36 тыс.
Why Should You Use TypeScript Instead of Javascript
6:12
Tips For Using Async/Await in JavaScript
16:26
Просмотров 396 тыс.
ESNext for await of loop
10:06
Просмотров 6 тыс.
5 Async + Await Error Handling Strategies
18:11
Просмотров 22 тыс.