forEach Array Method | JavaScript Tutorial

Поділитися
Вставка
  • Опубліковано 29 гру 2024

КОМЕНТАРІ • 124

  • @FlorinPop
    @FlorinPop  4 роки тому +11

    Check out the other videos in the JavaScript Array Methods series: ua-cam.com/play/PLgBH1CvjOA62PBFIDq55-S6Beivje30A2.html

  • @fahadzakir6397
    @fahadzakir6397 3 роки тому +24

    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 роки тому +2

      bro i have not understood,here what is let count
      how empty object declaration will acess that array,

    • @fahadzakir6397
      @fahadzakir6397 3 роки тому +6

      @@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 роки тому +24

      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 роки тому +3

      @@fahadzakir6397 Legend!

    • @jaisharma8056
      @jaisharma8056 2 роки тому +1

      @@fahadzakir6397 thank you so much fahad zakir

  • @nithish_raina
    @nithish_raina 3 роки тому +3

    This helped me to build a solution for returning a max char from an array. Thnx for this tutorial and whole playlists.

  • @MrRafael1912
    @MrRafael1912 4 роки тому +7

    Multiple uploads and they are all very clear and concise.

    • @FlorinPop
      @FlorinPop  4 роки тому +1

      I’m happy you like them! ☺️

  • @rotrose7531
    @rotrose7531 4 роки тому +14

    Just found your tutorials, easy to understand, Thank you.

    • @FlorinPop
      @FlorinPop  4 роки тому +1

      Happy to hear that 😃

  • @techno_abhishek8982
    @techno_abhishek8982 4 роки тому +6

    How you using vscode terminal to output those javascript code?

    • @vanibannuru
      @vanibannuru 6 місяців тому

      In the terminal you need to write a node.and your file name

  • @a_z3730
    @a_z3730 4 роки тому +4

    this kind of videos are the best when u are beginner, thank u

  • @HamzaKhan-ix3gn
    @HamzaKhan-ix3gn 3 роки тому +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

  • @nagendrach1849
    @nagendrach1849 3 роки тому +1

    Nice explainer, buy how you using vscode terminal to output those javascript code?

  • @kishoreandra
    @kishoreandra 4 роки тому +1

    I am not gonna miss this !!!

  • @weilin5804
    @weilin5804 2 роки тому +6

    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 Рік тому +1

      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

  • @RahulRai-vw3dw
    @RahulRai-vw3dw 2 роки тому +1

    can you tell me how is your output is showing in the terminal

  • @rajkiranchaudhary8769
    @rajkiranchaudhary8769 4 роки тому +2

    I am not getting my console.log value in terminal. How can I get my values displayed in the terminal?????

  • @apaarjain
    @apaarjain 4 місяці тому

    these lessons are amazing.

    • @FlorinPop
      @FlorinPop  4 місяці тому

      Really glad you like them 🙏

  • @siachmad
    @siachmad 3 роки тому +2

    Thank you Sir, your tutorial is very clear and show that we can use the method in different way, thank you so much Sir

  • @antochitic
    @antochitic 4 роки тому +1

    JS daily pill! Keep up the good work! 🙏

  • @reedreal
    @reedreal 4 роки тому +4

    Hi Florin, thanks for the good job you are doing. does ForEach also work like .reduce?

  • @MaxProgramming
    @MaxProgramming 4 роки тому +5

    One doubt, why do we use count[item] instead of count.item even if it's an object?

    • @FlorinPop
      @FlorinPop  4 роки тому +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 роки тому +1

      @@FlorinPop Oh so [] this is to set a new property to the object. I just saw it in arrays beforehand. Thanks

  • @Yakuzanis
    @Yakuzanis Рік тому

    thank you for this great explanation

  • @webgraphics2706
    @webgraphics2706 3 роки тому +1

    You are the BEST... That's the fact

  • @TheEvenClan
    @TheEvenClan 4 роки тому +1

    Thank you for all your videos!

  • @republicofchina8872
    @republicofchina8872 4 роки тому +1

    quick and good explanation 👍

  • @stubborntommy
    @stubborntommy 4 роки тому +1

    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.

  • @tomsantos220
    @tomsantos220 2 роки тому

    very good content theacher !!! thaks

  • @riyasahamed2016
    @riyasahamed2016 4 роки тому +2

    Really a massive I am in your fan!

  • @gayathriv2274
    @gayathriv2274 4 роки тому +3

    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

  • @niesamain1871
    @niesamain1871 4 роки тому +2

    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

  • @Estoyvendiendo
    @Estoyvendiendo 4 роки тому +4

    is this basically a for loop?

    • @FlorinPop
      @FlorinPop  4 роки тому +2

      Yes, but it has a few advantages. I should do a video on that.

    • @Estoyvendiendo
      @Estoyvendiendo 4 роки тому +1

      @@FlorinPop thanks bro, this programming is hard. I'll get to your level someday

  • @justinxten4real657
    @justinxten4real657 3 роки тому

    Nice break down currently in a boot camp and this will definitely be of use

  • @gonzaloperezrojas9362
    @gonzaloperezrojas9362 4 роки тому +1

    "let count = {}" means that you declare a variable with an undefined value?

    • @NiiiiiiCK
      @NiiiiiiCK 3 роки тому

      No thats empty array

    • @cristiano1706
      @cristiano1706 Рік тому

      ​@@NiiiiiiCK nope thats an empty object

  • @inchasto
    @inchasto 3 роки тому

    please , what addon i have to install to run JS in VS code?

  • @zoirradjabov1420
    @zoirradjabov1420 Рік тому

    Nice explanation! It is is exactly that I was after🤓

  • @NedumEze
    @NedumEze 3 роки тому

    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.

  • @billteale2306
    @billteale2306 4 роки тому +1

    Is there a similar tutorial that would help me decode a json file, perhaps using php?

  • @MrRisn
    @MrRisn 2 роки тому

    thank you very much for this very clear explanation! it really helped me a lot!!!

  • @aaronargottelopez3488
    @aaronargottelopez3488 4 роки тому

    I am thankful to you. Great video.

  • @mrhashtag5376
    @mrhashtag5376 4 роки тому

    hey pls help me.... i dnt understand the let count={} and how the count[item]++ works ?

  • @andresviveros3994
    @andresviveros3994 2 роки тому +1

    if foreach doesnt return anything how can it be used? Thanks

    • @FlorinPop
      @FlorinPop  2 роки тому

      You manipulate data inside it

    • @ziggyjuarez8544
      @ziggyjuarez8544 Рік тому

      He's manipulating the count object specifically

  • @BestNutochka
    @BestNutochka 2 роки тому

    Thank you so much!!!

  • @xstrafez_c2017
    @xstrafez_c2017 4 роки тому +3

    Thanks so much!

  • @overstrides
    @overstrides 4 роки тому

    Thank you for the great video!

  • @qatadd8313
    @qatadd8313 3 роки тому

    You Are Amazing Thank You A Lot

  • @lenhu7089
    @lenhu7089 4 роки тому

    love this topic, thank you so much

  • @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?

  • @levin1160
    @levin1160 3 роки тому

    Learned some new stuff with the object counter, nice!

  • @multitudes389
    @multitudes389 4 роки тому +1

    really good!

  • @bahiaanis331
    @bahiaanis331 4 роки тому

    thank you for this tuto , how can i use the terminal like that please

  • @linaskaskonas4596
    @linaskaskonas4596 3 роки тому

    How to download this coding platform?

  • @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 роки тому +1

      The sum was not returned. It was calculated inside the function.

  • @nxuanthanhf
    @nxuanthanhf 3 роки тому

    How do you clean the terminal?

  • @harrinsonA
    @harrinsonA 4 роки тому

    Me gusto el Tutorial mano!

  • @FavourAkpasi
    @FavourAkpasi 3 роки тому

    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  3 роки тому +2

      I used nodemon. Made a video on my channel about it

    • @FavourAkpasi
      @FavourAkpasi 3 роки тому +2

      @@FlorinPop a link to the video would be very helpful

    • @FavourAkpasi
      @FavourAkpasi 3 роки тому +1

      i found the video. thank you.

    • @blueleaf9129
      @blueleaf9129 2 роки тому +1

      @@FavourAkpasi instead of using nodemon, u can use the live server extension

  • @CristinaSoare-u4w
    @CristinaSoare-u4w Рік тому

    Hi Florin, can you do a similar playlist of videos as you have for array methods but for strings? Thanks!

    • @FlorinPop
      @FlorinPop  Рік тому +1

      Will create more content around it 😄

    • @CristinaSoare-u4w
      @CristinaSoare-u4w Рік тому

      @@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  Рік тому

      @@CristinaSoare-u4w Sigur, scrie-mi pe Twitter si rezolvam 😁

  • @sharaths2294
    @sharaths2294 3 роки тому

    thanks man

  • @sami-w4dux
    @sami-w4dux 3 роки тому

    How to get output like him ?

  • @leagueahri6128
    @leagueahri6128 3 роки тому

    thank you rebeccaPurple man

  • @shamwela_
    @shamwela_ 4 роки тому

    I really like your accent!

  • @imtusharkhanna
    @imtusharkhanna 4 роки тому +3

    Fact: Do you know you can't break from forEach loop? If yes, What is the reason?

    • @multitudes389
      @multitudes389 4 роки тому +1

      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

  • @aaronargottelopez3488
    @aaronargottelopez3488 4 роки тому

    Thanks!

  • @jkovert
    @jkovert 2 роки тому

    got yo million yet yo

  • @codex1758
    @codex1758 3 роки тому

    Where are you from?

  • @AllenMarsam
    @AllenMarsam 3 роки тому

    thanks

  • @ashleysouffrant1320
    @ashleysouffrant1320 4 роки тому +3

    Wait I thought you were taking a pause?

  • @lucasdamasceno7068
    @lucasdamasceno7068 Рік тому

    thanksss

  • @marc1an4
    @marc1an4 2 роки тому

    your code could be done in almost only two lines, but thank you so much.

  • @aryaadinulfadlan8998
    @aryaadinulfadlan8998 3 роки тому

    love you florin

  • @imnkur
    @imnkur 4 роки тому +1

    Wooaah

  • @hazimmohammed5345
    @hazimmohammed5345 2 роки тому

    Hi plss reply me i need help

  • @rohansolse67
    @rohansolse67 4 роки тому

    Cool

  • @nosense7859
    @nosense7859 3 роки тому

    vip pro

  • @mattsmith6828
    @mattsmith6828 Рік тому

    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.

  • @Mobin_atrzade
    @Mobin_atrzade 3 роки тому

    وری گود

  • @schemagroup1
    @schemagroup1 3 роки тому

    I personally hate Javascript it's so loosely typed, with no structure in mind Garbage!!

  • @marlonmartins23
    @marlonmartins23 2 роки тому

    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_12
    @Skura_12 2 роки тому

    Thanks!