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 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”
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 :)
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
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
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 ?
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
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.
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
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?
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?
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 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
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
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.
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);
Check out the other videos in the JavaScript Array Methods series: ua-cam.com/play/PLgBH1CvjOA62PBFIDq55-S6Beivje30A2.html
how this part work if(count[item])
{
count[item]++;
}
else
{
count[item] = 1;
}
@@studiorda😅
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.
bro i have not understood,here what is let count
how empty object declaration will acess that array,
@@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”
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 :)
@@fahadzakir6397 Legend!
@@fahadzakir6397 thank you so much fahad zakir
This helped me to build a solution for returning a max char from an array. Thnx for this tutorial and whole playlists.
Multiple uploads and they are all very clear and concise.
I’m happy you like them! ☺️
Just found your tutorials, easy to understand, Thank you.
Happy to hear that 😃
How you using vscode terminal to output those javascript code?
In the terminal you need to write a node.and your file name
this kind of videos are the best when u are beginner, thank u
Happy to hear that!
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
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
Nice explainer, buy how you using vscode terminal to output those javascript code?
I am not gonna miss this !!!
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 ?
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
can you tell me how is your output is showing in the terminal
I am not getting my console.log value in terminal. How can I get my values displayed in the terminal?????
these lessons are amazing.
Really glad you like them 🙏
Thank you Sir, your tutorial is very clear and show that we can use the method in different way, thank you so much Sir
JS daily pill! Keep up the good work! 🙏
Hi Florin, thanks for the good job you are doing. does ForEach also work like .reduce?
One doubt, why do we use count[item] instead of count.item even if it's an object?
Because item stands for 'a' then 'b' then 'c' and those are the properties we want to set and not the .item property.
@@FlorinPop Oh so [] this is to set a new property to the object. I just saw it in arrays beforehand. Thanks
thank you for this great explanation
You are the BEST... That's the fact
Thank you for all your videos!
quick and good explanation 👍
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.
very good content theacher !!! thaks
Really a massive I am in your fan!
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
very true
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
man,r u there?
is this basically a for loop?
Yes, but it has a few advantages. I should do a video on that.
@@FlorinPop thanks bro, this programming is hard. I'll get to your level someday
Nice break down currently in a boot camp and this will definitely be of use
"let count = {}" means that you declare a variable with an undefined value?
No thats empty array
@@NiiiiiiCK nope thats an empty object
please , what addon i have to install to run JS in VS code?
Nice explanation! It is is exactly that I was after🤓
🙏
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.
Is there a similar tutorial that would help me decode a json file, perhaps using php?
I don’t know PHP :/
thank you very much for this very clear explanation! it really helped me a lot!!!
I am thankful to you. Great video.
hey pls help me.... i dnt understand the let count={} and how the count[item]++ works ?
if foreach doesnt return anything how can it be used? Thanks
You manipulate data inside it
He's manipulating the count object specifically
Thank you so much!!!
Thanks so much!
Thank you for the great video!
You Are Amazing Thank You A Lot
love this topic, thank you so much
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?
Learned some new stuff with the object counter, nice!
really good!
thank you for this tuto , how can i use the terminal like that please
Node
How to download this coding platform?
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?
The sum was not returned. It was calculated inside the function.
How do you clean the terminal?
just type clear 😁
CTRL + L
Me gusto el Tutorial mano!
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.
I used nodemon. Made a video on my channel about it
@@FlorinPop a link to the video would be very helpful
i found the video. thank you.
@@FavourAkpasi instead of using nodemon, u can use the live server extension
Hi Florin, can you do a similar playlist of videos as you have for array methods but for strings? Thanks!
Will create more content around it 😄
@@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
@@CristinaSoare-u4w Sigur, scrie-mi pe Twitter si rezolvam 😁
thanks man
How to get output like him ?
thank you rebeccaPurple man
I really like your accent!
Fact: Do you know you can't break from forEach loop? If yes, What is the reason?
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
Thanks!
got yo million yet yo
Where are you from?
thanks
Wait I thought you were taking a pause?
Check out the previous Live Stream 😅
Yeah, check it out
thanksss
your code could be done in almost only two lines, but thank you so much.
You’re welcome
love you florin
Wooaah
Hi plss reply me i need help
Cool
vip pro
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.
وری گود
I personally hate Javascript it's so loosely typed, with no structure in mind Garbage!!
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);
Thanks!