forEach Array Method | JavaScript Tutorial

  Рет қаралды 221,122

Florin Pop

Florin Pop

Күн бұрын

👉 Daily Coding Challenges: iCodeThis.com/?ref=ytb-js-for...
In this tutorial, we're going to learn about the #forEach #JavaScript #Array Method and how we can use it to call a provided function once for each element inside the array.
JS Array Methods Playlist: • JavaScript Array Methods
---
Support my channel:
💜 Become a Member of the Poppers Family and receive special perks: kzfaq.infojoin
💜 Donate via StreamLabs: streamlabs.com/florinpop2/
💜 Donate via PayPal: paypal.me/florinpop17
💜 Become a patron: / florinpop17
Thank you! 🙏
---
👨‍👩‍👧‍👦 Join the Discord family: / discord
---
Follow me on:
📃 Website/Blog: florin-pop.com
👉 Twitter: / florinpop1705
👉 Linkedin: / florinpop17
👉 Instagram: / florinpop17
👉 Facebook: / florinpop17
👉 Github: github.com/florinpop17
👉 Dev.to: dev.to/florinpop17
👉 Twitch: twitch.com/florinpop17

Пікірлер: 119
@FlorinPop
@FlorinPop 4 жыл бұрын
Check out the other videos in the JavaScript Array Methods series: kzfaq.info/sun/PLgBH1CvjOA62PBFIDq55-S6Beivje30A2
@studiorda
@studiorda 3 жыл бұрын
how this part work if(count[item]) { count[item]++; } else { count[item] = 1; }
@charafeddineberahmoune9370
@charafeddineberahmoune9370 9 ай бұрын
​@@studiorda😅
@nithish_raina
@nithish_raina 3 жыл бұрын
This helped me to build a solution for returning a max char from an array. Thnx for this tutorial and whole playlists.
@rotrose7531
@rotrose7531 4 жыл бұрын
Just found your tutorials, easy to understand, Thank you.
@FlorinPop
@FlorinPop 4 жыл бұрын
Happy to hear that 😃
@fahadzakir6397
@fahadzakir6397 3 жыл бұрын
For anyone else like me who didn't understand the last Object loop: The last part if (count[item]) is true if the object has a property and then it goes to the condition of incrementing the property value ++. If it is false then it's assigned that property with the value 1.
@chellaack1644
@chellaack1644 3 жыл бұрын
bro i have not understood,here what is let count how empty object declaration will acess that array,
@fahadzakir6397
@fahadzakir6397 3 жыл бұрын
@@chellaack1644 so let count like you said is an empty object declared just like you would do with an empty variable. Let’s say we have an object called sampleObj with “name” as a property. You can access it like this: sampleObj[“name”] and a way to give this sampleObj property “name” a value is like this: sampleObj[“name”]=“Tom”
@fahadzakir6397
@fahadzakir6397 3 жыл бұрын
So In the video, in the if else, it first checks to see if the count empty object has the letter ‘a’ as a property, so count[‘a’] (first-loop) is undefined then it goes to the else condition and gives assigns that property with a value of 1. So we now have count{a:1} The second time it runs across the letter ‘a’ in the loop, it now exists with the value 1 so it tells it to increment that value ++ thus making count{a:2} and then keeps looping and adding, properties and values. Hope this makes sense :)
@joaobertuga3601
@joaobertuga3601 2 жыл бұрын
@@fahadzakir6397 Legend!
@jaisharma8056
@jaisharma8056 2 жыл бұрын
@@fahadzakir6397 thank you so much fahad zakir
@justinxten4real657
@justinxten4real657 2 жыл бұрын
Nice break down currently in a boot camp and this will definitely be of use
@siachmad
@siachmad 3 жыл бұрын
Thank you Sir, your tutorial is very clear and show that we can use the method in different way, thank you so much Sir
@MrRafael1912
@MrRafael1912 4 жыл бұрын
Multiple uploads and they are all very clear and concise.
@FlorinPop
@FlorinPop 4 жыл бұрын
I’m happy you like them! ☺️
@HamzaKhan-ix3gn
@HamzaKhan-ix3gn 2 жыл бұрын
hey florin, i'm new in javascript n i want to become expert in javascript, i have seen first lecture on array on youtube and this is you, you have done a wonder full job, very easy understandable code, now i'm thinking i should follow the whole this video series..! keep going like this
@rpralica
@rpralica 2 жыл бұрын
If You want to be js expert take course from Jonas Smedthmann "The Complete JavaScript Course 2022: From Zero to Expert! " .This is great course belive ne
@MrRisn
@MrRisn Жыл бұрын
thank you very much for this very clear explanation! it really helped me a lot!!!
@reedreal
@reedreal 4 жыл бұрын
Hi Florin, thanks for the good job you are doing. does ForEach also work like .reduce?
@antochitic
@antochitic 4 жыл бұрын
JS daily pill! Keep up the good work! 🙏
@TheEvenClan
@TheEvenClan 4 жыл бұрын
Thank you for all your videos!
@Yakuzanis
@Yakuzanis 9 ай бұрын
thank you for this great explanation
@a_z3730
@a_z3730 4 жыл бұрын
this kind of videos are the best when u are beginner, thank u
@FlorinPop
@FlorinPop 4 жыл бұрын
Happy to hear that!
@lenhu7089
@lenhu7089 3 жыл бұрын
love this topic, thank you so much
@aaronargottelopez3488
@aaronargottelopez3488 3 жыл бұрын
I am thankful to you. Great video.
@overstrides
@overstrides 4 жыл бұрын
Thank you for the great video!
@kishoreandra
@kishoreandra 4 жыл бұрын
I am not gonna miss this !!!
@weilin5804
@weilin5804 2 жыл бұрын
Hi Florin, thanks for your great tutorial. In the end of the video, inside the if parentheses, it's only count[item], normally inside if parentheses would be conditions with comparison operators, so I'm not quite understand what does if (count[item]) stands for, could you explain more for this ?
@blackpurple9163
@blackpurple9163 Жыл бұрын
It means if the item (element in the array) exists, then execute the if statement, we can't leave if ( ) empty, it'll throw error, and since count is an empty object, we can use dot notation or bracket notation to access object's inner keys, so it can be count.item or count[item], both should work
@republicofchina8872
@republicofchina8872 4 жыл бұрын
quick and good explanation 👍
@xstrafez_c2017
@xstrafez_c2017 4 жыл бұрын
Thanks so much!
@MrTomequ
@MrTomequ 3 жыл бұрын
Hi, thanks for a great tutorial and I have a small question. How can I get the same result in the terminal - I mean without an unnecessary code (like: $ node "c:\Users\thomas\Desktop\Exercises\script.js"), only pure result, like on your video. Regards, Thomas.
@nagendrach1849
@nagendrach1849 2 жыл бұрын
Nice explainer, buy how you using vscode terminal to output those javascript code?
@riyasahamed2016
@riyasahamed2016 4 жыл бұрын
Really a massive I am in your fan!
@tomsantos220
@tomsantos220 2 жыл бұрын
very good content theacher !!! thaks
@techno_abhishek8982
@techno_abhishek8982 4 жыл бұрын
How you using vscode terminal to output those javascript code?
@qatadd8313
@qatadd8313 3 жыл бұрын
You Are Amazing Thank You A Lot
@harrinsonA
@harrinsonA 4 жыл бұрын
Me gusto el Tutorial mano!
@BestNutochka
@BestNutochka Жыл бұрын
Thank you so much!!!
@webgraphics2706
@webgraphics2706 3 жыл бұрын
You are the BEST... That's the fact
@multitudes389
@multitudes389 4 жыл бұрын
really good!
@FavourAkpasi
@FavourAkpasi 2 жыл бұрын
this was very helpful, i enjoyed every moment of the tutorial and i understand array functions better now. just 1 question how do I display my console log in vs code.
@FlorinPop
@FlorinPop 2 жыл бұрын
I used nodemon. Made a video on my channel about it
@FavourAkpasi
@FavourAkpasi 2 жыл бұрын
@@FlorinPop a link to the video would be very helpful
@FavourAkpasi
@FavourAkpasi 2 жыл бұрын
i found the video. thank you.
@blueleaf9129
@blueleaf9129 Жыл бұрын
@@FavourAkpasi instead of using nodemon, u can use the live server extension
@zoirradjabov1420
@zoirradjabov1420 Жыл бұрын
Nice explanation! It is is exactly that I was after🤓
@FlorinPop
@FlorinPop Жыл бұрын
🙏
@levin1160
@levin1160 2 жыл бұрын
Learned some new stuff with the object counter, nice!
@RahulRai-vw3dw
@RahulRai-vw3dw 2 жыл бұрын
can you tell me how is your output is showing in the terminal
@aaronargottelopez3488
@aaronargottelopez3488 3 жыл бұрын
Thanks!
@NedumEze
@NedumEze 2 жыл бұрын
Thanks for the Tutorial. But please can I send you forEach code I wrote that won't work at all? Maybe you can show me what am doing wrong.
@gayathriv2274
@gayathriv2274 4 жыл бұрын
Hi, how about a bit deeper dive of why async won't work inside forEach. I just know the fact but would like to know the explanation from you
@samcodes2912
@samcodes2912 3 жыл бұрын
very true
@rajkiranchaudhary8769
@rajkiranchaudhary8769 3 жыл бұрын
I am not getting my console.log value in terminal. How can I get my values displayed in the terminal?????
@inchasto
@inchasto 2 жыл бұрын
please , what addon i have to install to run JS in VS code?
@user-ro3dg7sz6b
@user-ro3dg7sz6b Жыл бұрын
Hi Florin, can you do a similar playlist of videos as you have for array methods but for strings? Thanks!
@FlorinPop
@FlorinPop Жыл бұрын
Will create more content around it 😄
@user-ro3dg7sz6b
@user-ro3dg7sz6b Жыл бұрын
@@FlorinPop wow didn't expect a response! fac acum un bootcamp si mi-au fost de mare ajutor video-urile tale! as fi foarte incantata daca ai fi dispus sa imi acorzi o ora din timpul tau intr-o zi pentru niste sfaturi. Happy to pay you for it! :D from a fellow Mureseanca
@FlorinPop
@FlorinPop Жыл бұрын
@@user-ro3dg7sz6b Sigur, scrie-mi pe Twitter si rezolvam 😁
@sharaths2294
@sharaths2294 2 жыл бұрын
thanks man
@shamwela_
@shamwela_ 4 жыл бұрын
I really like your accent!
@mrhashtag5376
@mrhashtag5376 3 жыл бұрын
hey pls help me.... i dnt understand the let count={} and how the count[item]++ works ?
@andejoel55
@andejoel55 2 жыл бұрын
let sum = 0; number.forEach(function(value){ sum += value; }) console.log(sum); this would generate the same answer, is there any thing I should know about using it?
@MaxProgramming
@MaxProgramming 4 жыл бұрын
One doubt, why do we use count[item] instead of count.item even if it's an object?
@FlorinPop
@FlorinPop 4 жыл бұрын
Because item stands for 'a' then 'b' then 'c' and those are the properties we want to set and not the .item property.
@MaxProgramming
@MaxProgramming 4 жыл бұрын
@@FlorinPop Oh so [] this is to set a new property to the object. I just saw it in arrays beforehand. Thanks
@AllenMarsam
@AllenMarsam 3 жыл бұрын
thanks
@billteale2306
@billteale2306 4 жыл бұрын
Is there a similar tutorial that would help me decode a json file, perhaps using php?
@FlorinPop
@FlorinPop 4 жыл бұрын
I don’t know PHP :/
@bahiaanis331
@bahiaanis331 3 жыл бұрын
thank you for this tuto , how can i use the terminal like that please
@NiiiiiiCK
@NiiiiiiCK 2 жыл бұрын
Node
@gonzaloperezrojas9362
@gonzaloperezrojas9362 3 жыл бұрын
"let count = {}" means that you declare a variable with an undefined value?
@NiiiiiiCK
@NiiiiiiCK 2 жыл бұрын
No thats empty array
@cristiano1706
@cristiano1706 Жыл бұрын
​@@NiiiiiiCK nope thats an empty object
@lucasdamasceno7068
@lucasdamasceno7068 Жыл бұрын
thanksss
@leagueahri6128
@leagueahri6128 3 жыл бұрын
thank you rebeccaPurple man
@niesamain1871
@niesamain1871 3 жыл бұрын
1:25 - yeah coming from C/C++, Java, and Python but still... this doesn't make sense to meeeee😭😭😭 like what are those 3 parameters in the callback definition?😭😭😭 I can't understand JavaScript man
@thiyageshkanna
@thiyageshkanna 3 жыл бұрын
man,r u there?
@linaskaskonas4596
@linaskaskonas4596 2 жыл бұрын
How to download this coding platform?
@sami-w4dux
@sami-w4dux 2 жыл бұрын
How to get output like him ?
@MrShardrain
@MrShardrain 4 жыл бұрын
is this basically a for loop?
@FlorinPop
@FlorinPop 4 жыл бұрын
Yes, but it has a few advantages. I should do a video on that.
@MrShardrain
@MrShardrain 4 жыл бұрын
@@FlorinPop thanks bro, this programming is hard. I'll get to your level someday
@jkovert
@jkovert 2 жыл бұрын
got yo million yet yo
@imtusharkhanna
@imtusharkhanna 4 жыл бұрын
Fact: Do you know you can't break from forEach loop? If yes, What is the reason?
@multitudes389
@multitudes389 4 жыл бұрын
The forEach loop executes a callback function on each element of the array and therefore returning or breaking from it, would just return/break from the callback and not the loop. Also forEach is part of the functional programming paradigm where we want to use pure functions. Pure functions take some input and return some output based on that input. They are simple and reliable. And they do not produce side effects
@bernardus3289
@bernardus3289 2 жыл бұрын
Everywhere I read about forEach it says that the method does not return anything but in this tutorial the sum was clearly returned. WUT??? Am I missing something here?
@FlorinPop
@FlorinPop 2 жыл бұрын
The sum was not returned. It was calculated inside the function.
@codex1758
@codex1758 2 жыл бұрын
Where are you from?
@rohansolse67
@rohansolse67 3 жыл бұрын
Cool
@andresviveros3994
@andresviveros3994 2 жыл бұрын
if foreach doesnt return anything how can it be used? Thanks
@FlorinPop
@FlorinPop 2 жыл бұрын
You manipulate data inside it
@ziggyjuarez8544
@ziggyjuarez8544 10 ай бұрын
He's manipulating the count object specifically
@marc1an4
@marc1an4 Жыл бұрын
your code could be done in almost only two lines, but thank you so much.
@FlorinPop
@FlorinPop Жыл бұрын
You’re welcome
@n.xuanthanh
@n.xuanthanh 2 жыл бұрын
How do you clean the terminal?
@osama7646
@osama7646 2 жыл бұрын
just type clear 😁
@giodona1511
@giodona1511 2 жыл бұрын
CTRL + L
@ashleysouffrant1320
@ashleysouffrant1320 4 жыл бұрын
Wait I thought you were taking a pause?
@FlorinPop
@FlorinPop 4 жыл бұрын
Check out the previous Live Stream 😅
@MaxProgramming
@MaxProgramming 4 жыл бұрын
Yeah, check it out
@imnkur
@imnkur 4 жыл бұрын
Wooaah
@aryaadinulfadlan8998
@aryaadinulfadlan8998 2 жыл бұрын
love you florin
@hazimmohammed5345
@hazimmohammed5345 2 жыл бұрын
Hi plss reply me i need help
@nosense7859
@nosense7859 3 жыл бұрын
vip pro
@Mobin_atrzade
@Mobin_atrzade 3 жыл бұрын
وری گود
@mattsmith6828
@mattsmith6828 10 ай бұрын
I've been hearing a lot of.... distain for the "forEach" method. Especially in the context of asynchronous code. Not an expert, but be careful using this method.
@schemagroup1
@schemagroup1 3 жыл бұрын
I personally hate Javascript it's so loosely typed, with no structure in mind Garbage!!
@marlonmartins23
@marlonmartins23 Жыл бұрын
I found an easier way, const countries = ['Argentina', 'Brazil', 'Argentina', 'Portugal', 'Brazil']; // Keep track count of every country let count = {}; countries.forEach((country) => { count[country] = (count[country] || 0) + 1; }) console.log(count);
@Skura_54
@Skura_54 Жыл бұрын
Thanks!
map Array Method | JavaScript Tutorial
6:49
Florin Pop
Рет қаралды 84 М.
slice Array Method | JavaScript Tutorial
3:34
Florin Pop
Рет қаралды 60 М.
$10,000 Every Day You Survive In The Wilderness
26:44
MrBeast
Рет қаралды 135 МЛН
Backstage 🤫 tutorial #elsarca #tiktok
00:13
Elsa Arca
Рет қаралды 39 МЛН
СНЕЖКИ ЛЕТОМ?? #shorts
00:30
Паша Осадчий
Рет қаралды 6 МЛН
filter Array Method | JavaScript Tutorial
4:57
Florin Pop
Рет қаралды 58 М.
Inheritance in JavaScript - Prototypal Inheritance tutorial
20:06
JavaScript Array forEach Method
4:40
Steve Griffith - Prof3ssorSt3v3
Рет қаралды 91 М.
Array Methods in JavaScript | 17 Useful Methods
42:39
DoableDanny
Рет қаралды 48 М.
8 Must Know JavaScript Array Methods
10:05
Web Dev Simplified
Рет қаралды 1 МЛН
Async JS Crash Course - Callbacks, Promises, Async Await
24:31
Traversy Media
Рет қаралды 1,4 МЛН
Shell scripting in nutshell
18:49
ajay narain mathur
Рет қаралды 8
#1: Array .map() Method | JavaScript Array Methods
10:50
QiroLab
Рет қаралды 3 М.
$10,000 Every Day You Survive In The Wilderness
26:44
MrBeast
Рет қаралды 135 МЛН