16.6: Array Functions: map() and fill() - Topics of JavaScript/ES6

Поделиться
HTML-код
  • Опубликовано: 1 окт 2024
  • In this video, I discuss two array functions in JavaScript: map() and fill().
    🎥 Next Video: • 16.7: Array Functions:...
    🔗 MDN's Array Documentation: developer.mozi...
    🎥 Prototypes in JavaScript: • 9.19: Prototypes in Ja...
    🚂 The Coding Train website: thecodingtrain....
    💖 Support this channel on Patreon: / codingtrain
    🛒 To buy Coding Train merchandise: www.designbyhu...
    📚 Book recommendations: www.amazon.com...
    💻 github.com/Cod...
    🎥 For an Introduction to Programming: • Start learning here!
    🎥 For More Coding Challenges: • Coding Challenges
    🔗 p5js.org/
    🔗 processing.org
    📄 Code of Conduct: github.com/Cod...

Комментарии • 184

  • @copypaste_pro
    @copypaste_pro 5 лет назад +128

    Most enjoyable JS tutorials ever, I don't even need coffee...

    • @SakosTechSpot
      @SakosTechSpot 4 года назад +1

      Are you saying you don't need... Java?

    • @spht9ng
      @spht9ng 2 года назад

      @@SakosTechSpot nah. just java.....script

  • @taricov4662
    @taricov4662 4 года назад +15

    I did not think for once that I could enjoy watching JS tutorials!

  • @soyitiel
    @soyitiel 6 лет назад +101

    Dude, you get too excited, I love it!!

    • @brunoribeiro1383
      @brunoribeiro1383 5 лет назад +1

      He almost died at some point there, I did not know it was so dangerous to make a youtube video

    • @ravalravi882
      @ravalravi882 4 года назад +2

      What is The problem with that ??? I think Its relly help us to stick to the video and entertant us while learning . what You say
      dude

  • @benjaminghys99
    @benjaminghys99 6 лет назад +91

    did he just say "Welcome back bby" ? xD lmao

  • @lilyanezlibenmeradi7291
    @lilyanezlibenmeradi7291 6 лет назад +32

    Every time I watch a coding train video I'm happy.
    (plus, I can't help myself thinking "This guy is the cutest thing on Earth" lol).

  • @gibblesham373
    @gibblesham373 3 года назад +10

    This guy is the type of guy that can make everyone in the room feel happy even if you're sad that day

  • @SuperYara22
    @SuperYara22 5 лет назад +12

    I really appreciate the work you put into creating these videos. You are my to go guy if when I can't understand a concept. THANK YOU!!

  • @anirudhbhardwaj8373
    @anirudhbhardwaj8373 6 лет назад +18

    You have thought me so much. Thank you! Ur my favourite youtuber.

    • @Rightlime7923
      @Rightlime7923 6 лет назад +3

      He is the greatest programmer in history of mankind

    • @shoebmoin10
      @shoebmoin10 6 лет назад

      Flash Drive surely the most energetic one though !!

  • @jl-dq5ch
    @jl-dq5ch 5 лет назад +9

    I love how weird this guy is. 10:32 i died XD Lol

  • @alvarezskinner
    @alvarezskinner 6 лет назад +6

    Man I wish I had a teacher like you in the past, like your teaching style, the way you make it look fun, and also have a good time and laughs watching your videos! Thanks!

  • @MrWrklez
    @MrWrklez 4 года назад +4

    Trying to learn about arrays and this guy has me laughing my ass off! Thanks for the great content!

  • @kantyDarius
    @kantyDarius 6 лет назад +39

    This guy is awesome

  • @tachmin4ever
    @tachmin4ever 4 года назад +2

    Maaaaan! I found this and I loved this tutorial jajajajaja The part of the glasses you made me laugh 😂 I love your energy and the way you explain

  • @farazqureshi3275
    @farazqureshi3275 3 года назад +1

    I m literally laughing during watching this video
    awesome Tutorial!!!!

  • @ga7853
    @ga7853 6 лет назад +5

    You are truly a great instructor, I love how you do things, you got me from the first video man.

  • @ramoswebdev4708
    @ramoswebdev4708 5 лет назад +10

    Thanks for that! Very well explained! I saw the entire video, but just for recaps:
    03:17 - map()
    08:32 - fill()

  • @ucielsola
    @ucielsola 3 года назад +1

    I can´t believe this content is free. I would hug you very strongly and then thank you for it.

  • @user-wn7et1ft9j
    @user-wn7et1ft9j 2 года назад +1

    stop calling me baby im starting to develop feelings for you

  • @crazyratlady9355
    @crazyratlady9355 3 года назад +2

    OMG YOU MAKE ME EXCITED TO CODE! Thanks so much. I'm so glad I found you!

  • @aresxena6632
    @aresxena6632 6 лет назад +1

    By default my localhost files open in Edge. Couldn't get the results, and began to question whether I'm reading the code in this tutorial correctly. Suddenly noticed he's using Chrome. Guess what happened? The code worked. What lesson did we learn today? Screw Edge for all its purposes.

  • @KillersAspect
    @KillersAspect 5 лет назад +4

    I genuinely have fun watching him while learning so much!

  • @ianchui
    @ianchui 6 лет назад +17

    nothing like coding train in the morning :^

  • @kecajable
    @kecajable 6 лет назад +3

    what about
    vals=Array.from({length:100},Math.random)
    :D

  • @mohammedfalih8713
    @mohammedfalih8713 3 года назад +1

    8:11 😂😂😂😂😂😂😂😂❤❤❤❤

  • @priyanshusaini8251
    @priyanshusaini8251 3 года назад +1

    Love From India ❤️

  • @SATPlay4Fun
    @SATPlay4Fun 6 лет назад +1

    To create an array with 100 random elements you can also do : Array.from({length: 100}, () => Math.random());

  • @toddtrulock6809
    @toddtrulock6809 2 года назад

    Glass are going expensive. There's gonna be more ads....5 seconds later... ad in 5,4,3,2,1.

  • @Fiona1Chan
    @Fiona1Chan 6 лет назад +1

    watching his video is much more better than reading my textbook

  • @ravalravi882
    @ravalravi882 4 года назад

    What is The difference Between map () and filter() method Guys ??? Both The Higher Order function will do the same job I think !
    can anyOne explain me ???
    Map() =>will Take The Function as aarnument and Return new array based On some condtion;Inside that function. and
    filter()=>will also Take the function as a argument and Return New array based on some condition inside that function;
    so How do we decide That when to use what ?????
    and awsome Video sir Love from India.

  • @陈瀚龙
    @陈瀚龙 4 года назад

    I'm replacing coffee with watching Coding Train every few hours.
    How are we not declaring vals at the very end? vals = Array(100)..... is it because we're creating a new array? I'm Java trained and just getting back into Javascript.

  • @dailylearning8386
    @dailylearning8386 3 года назад +1

    you are a legend, man

  • @hilkokriel5659
    @hilkokriel5659 5 лет назад +1

    At the rate code is being shortened, by 2020 you’ll type x and your code will intuitively return the meaning of life.
    Btw, the map function is super handy when manipulating arrays for Google Charts.

  • @rainman4684
    @rainman4684 3 года назад

    Lots of junk and mistakes that are incredibly distracting and confusing. The constant excessive hands gesticulation also does not contribute to the ideal perception. The author's unfounded amusement is only annoying. All that is missing is the jester's red nose. Of the originally planned four functions, managed to explain only one... Cool!
    Stylish, noisy, but it's not about learning javascript. Sorry.

  • @mario1ua
    @mario1ua 6 лет назад +1

    Some methods create new array, other change the existing array.
    For example sort() changes existing array.
    Great channel! Thanks

  • @4rled
    @4rled 4 года назад +1

    how is this guy so cool?

  • @rajaaekant
    @rajaaekant 4 года назад +1

    More people need to see this guy, I wish your channel grows much bigger and everyone can benefit from your teaching. Thanks a lot.

  • @sergejizhutkin4917
    @sergejizhutkin4917 2 года назад

    My english words isn't full, but i understand lesson, because of teacher's emotions )))) sorry for english

  • @wiksta4316
    @wiksta4316 3 года назад

    Some people enjoy when others fail... they could have moments of happiness watching this video ;-) Even it was success to make mistakes and find solution some people would enjoy that process as their ilussion to be generally better...

  • @Kidkromechan
    @Kidkromechan 3 года назад

    If only I had like 50% of your enthusiasm when talking.....

  • @juliodearaujo690
    @juliodearaujo690 4 года назад

    I don't know how I came here. BUT THANKS GOD! You are amazing! Even your pronuntiaton makes easy to understand to non english speakers. Thanks a lot!

  • @kingcole55
    @kingcole55 2 года назад

    Jesus christ my brain doesn't like this. I much prefer just writing it like a normal person tbh.

  • @knightfallgame
    @knightfallgame 3 года назад

    hi, cant find the video but in one of your vids a made a statement about the volume of your outro... please dismiss that, i discovered it was actually an issue with my sound equalizer haha. i fixed the issue now the volumes are synced well. thank you for your help with learning more about programming with javascript, it is a huge help

  • @scriptkeeper8243
    @scriptkeeper8243 3 года назад

    Thanks man, but crud you dither, get to the point already.....fluff stops at about 3:20

  • @shaberahamza5729
    @shaberahamza5729 3 года назад

    You made the fill and array the most confusing thing ever... It was unnecessary

  • @ZAZzzz1245
    @ZAZzzz1245 2 года назад

    Don't get to much excited while teaching . If u would get more excited u may break your whole setup

  • @dataacademy5870
    @dataacademy5870 4 года назад +1

    You are Awesome sir Its an honor to be your student. It was my first video lecture with you, sir.

  • @Michael-it6cu
    @Michael-it6cu Месяц назад

    its normall to drop your glasses like that, your brain works way more faster than normal at exact at that time so you lose motor function control.

  • @jenifer_jenno
    @jenifer_jenno 2 года назад

    Each and every corner you are explained very clearly and understandable... thank you keep doing

  • @zinsy23
    @zinsy23 4 года назад +1

    Love how you get excited about stuff no one really wants to talk about just for the sake of talking about it!

  • @SimonTiger
    @SimonTiger 4 года назад

    10:33 So...fill...isn't...a...higher order...function??

  • @amarmohammed5644
    @amarmohammed5644 4 года назад

    Normally don't like your style as you are a little to energetic but you this was perfect, thank you!

  • @Cornellie
    @Cornellie 8 месяцев назад

    I fucking love the energy and passion of these tutorials

  • @WhatsWrongWithNikhil
    @WhatsWrongWithNikhil 4 года назад

    lol,Try not to smoke weed before recording lectures next time.

  • @BrettCooper4702
    @BrettCooper4702 5 лет назад +1

    Thanks for doing these array tutorials, they really help.
    btw glasses being expensive, did you know, if you know your prescription you can order quality glasses from aliexpress. My latest pair cost $30us delivered, with a titanium frame and polarized lenses. So cheap that they can be more like a fashioned item than a specialty medical device.

    • @danielberinger5770
      @danielberinger5770 5 лет назад +1

      good tip

    • @dansxmods
      @dansxmods 5 лет назад

      Spending $30 on multiple pairs of glasses because they don't fit your face properly then buying different ones from aliexpress is a false economy :(

  • @PreCodeCamp
    @PreCodeCamp 5 месяцев назад

    Love your teaching! You are so goofy and that is what makes it great!

  • @yadusolparterre
    @yadusolparterre 4 года назад

    how come Array(100) works without the word "new"?

  • @thinkingmad1685
    @thinkingmad1685 3 года назад

    You just go on speaking random stuffs but really less content 😖

  • @chrisryan2765
    @chrisryan2765 2 года назад

    Hi great video thanks for clearing up the map() method!!, just one question and forgive me if it comes across critical, it certainly isnt its just to clarify my understanding. When you compress the program down into the anonymous function within the map argument, I notice you do vals = vals.map(x => x*2); vals being the original array we are doubling. Wont this mutate the original array? sorry just going through freecodecamp which states mutating the global variables is against the concept of functional programming? im sure youre just proving a point I just wanted to check your views. thanks for the lessons though I have learnt a lot through you!!

    • @zero11010
      @zero11010 2 года назад

      Great question! Check the docs. The map method creates a new array. It does not mutate there original array.
      Sometimes that’s wonderful. Sometimes it’s wasteful to take the time and space to create a new array.

  • @saurabh75prakash
    @saurabh75prakash 4 года назад

    I like your content, but your videos can be much shorter.

  • @SumitSingh-rw2vl
    @SumitSingh-rw2vl 2 года назад

    sir what's difference between map and filter method

  • @ninjarogue
    @ninjarogue 3 года назад

    lol i like how you kept going with it.. i actually do the same thing too i get caught up in these rabbit holes..

  • @frankie_goestohollywood
    @frankie_goestohollywood 5 лет назад

    Love your videos...especially when I'm feeling frustrated and need to revisit concepts...makes my learning enjoyable :-))))) thank you :-)))))))

  • @Wastefuldragon
    @Wastefuldragon 4 года назад

    Why does it only choose random numbers less than 1??

  • @bittubhardwaj685
    @bittubhardwaj685 6 лет назад

    hey shiffman which code block used for javascript plzz help i am big fan of u man....keep going man u are increadble

    • @TheCodingTrain
      @TheCodingTrain  6 лет назад

      This workflow video might help:
      ruclips.net/video/HZ4D3wDRaec/видео.html
      Also:
      sublime text: ruclips.net/video/UCHzlUiDD10/видео.html
      atom editor: ruclips.net/video/d3OcFexe9Ik/видео.html
      brackets: ruclips.net/video/nmZbhManVcY/видео.html
      codepen: ruclips.net/video/5gfUgNpS6kY/видео.html

  • @danishsiddiqui2468
    @danishsiddiqui2468 4 года назад

    I would fafsa every other course but pay you from my pocket

  • @ucthangnguyen4337
    @ucthangnguyen4337 3 года назад

    Can you explain the line "vals.fill(0).map()" cause I'm just new to js :

    • @zero11010
      @zero11010 2 года назад

      Start with the docs.
      Fill will take an array and replace contents with a static number. There are optional arguments to tell it which index to start and end at. So, you can say fill the array starting at index 5 and stop at index 7.
      Map looks at each element performs a function a returns a new array with some kind of change.
      So you started with an array. You mutated that original array with fill. Then you make a new array. Then you look at the mutated array and iterate over every element performing some actions on each element in the mutated array and place the result of those actions in order into the new array, then you return the new array.
      [1,2,3,4,5].fill(‘cat’).map( x => x += ‘s’)
      First I loop over the array. Each element is replaced with the string “cat”.
      Then I make a new array.
      Then I iterate over the modified original array, I look at each element and I add an “s” onto the end.
      Then I return the new array.
      [“cats”, “cats”, “cats”, “cats”, “cats”]
      The original array still exists, but remember that fill changed it.

  • @TheRegalboss
    @TheRegalboss 6 лет назад

    I really love the way you explain things these things. I understand it so much better now! You are a great teacher! And you are funny! :D I laughed so hard when you hit your glasses to the floor. :D I hope they are okey though. :) Keep this great tutorials coming! / Best regards from a Swedish JS noob :P

  • @TikTokGold-HotBoyChina
    @TikTokGold-HotBoyChina 2 года назад

    omg. so easy @@ thank you so muchhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh

  • @HeyDan1983
    @HeyDan1983 5 лет назад

    Would be great to have a coworker with your personality, thanks for the great videos!

  • @hcgreier6037
    @hcgreier6037 Год назад

    Best JS guy on YT!
    Thanks! 👍

  • @anthonythompson3806
    @anthonythompson3806 2 года назад

    A lot of methods in a short time! There is a method to the methods, apparently.

  • @hailahong3021
    @hailahong3021 5 лет назад

    How come your videos don’t have any ads?

  • @jokes108
    @jokes108 4 года назад

    8:22 😂

  • @rahulshewale5048
    @rahulshewale5048 2 года назад

    4:33

  • @wahhajs
    @wahhajs 6 лет назад

    You are better than elon musk

  • @erving_lanc324
    @erving_lanc324 4 года назад

    Would you say arrowhead functions are only particularly used for anonymous or call back functions rather than regular long functions with lots of syntax?

  • @pratikbankar4757
    @pratikbankar4757 3 года назад

    You are Awesome. Thank You.

  • @pmwut5
    @pmwut5 Год назад

    Enjoyed watching your video, great passion for explaining concepts clearly

  • @rdrahuldhiman19
    @rdrahuldhiman19 4 года назад

    that weird scratch sound is ...ehh idk

  • @TheAwesomeTati
    @TheAwesomeTati 3 года назад

    I LOVE THE POWER *_* thaaaanks!

  • @gulonamikaze3137
    @gulonamikaze3137 3 года назад

    man, u da best in explaining, thank u :dddddd

  • @lyawileh.a8741
    @lyawileh.a8741 4 года назад

    The man knows Javascript for sure. We really benefit from you. Do you have paid courses on Udemy? If yes, please share the link to your courses.

  • @prateekbhardwaj9943
    @prateekbhardwaj9943 4 года назад

    what an energy ... good animating way of teaching... in less time teach more stuff without letting us sleep and bored..u looks more funny on 1.5X speed :p

  • @programmingpi314
    @programmingpi314 2 года назад

    4:55 Right after he said there are going to be more ads, I got an ad.

  • @vivekraj9875
    @vivekraj9875 5 лет назад

    I'm the 1k-th liker😁😁😁😁

  • @fluffybunny510
    @fluffybunny510 2 года назад

    Map creates new glasses

  • @alephiumbattle
    @alephiumbattle 3 года назад

    Eres el puto amo!

  • @florentinflo1727
    @florentinflo1727 4 года назад

    Thank you for your funny way of teaching, very clear explications, i wish i discover your your channel earlier.

  • @charles-y2z6c
    @charles-y2z6c 5 лет назад

    Thank you, i am trying to get to expertise level ES6. Informative and entertaining

  • @apriyantotobing4304
    @apriyantotobing4304 4 года назад

    You broke your glass :''''

  • @PreetiGupta-jj6qg
    @PreetiGupta-jj6qg 4 года назад

    Hi . You are awesome. can u plz explain exports and module.exports difference ?

  • @jeremyrubio1531
    @jeremyrubio1531 2 года назад

    You're a smart teacher ! Thanks for sharing your knowledge with us

  • @avi12
    @avi12 6 лет назад +5

    10:50 You could also do:
    vals.fill((() => Math.random())());
    And I'm pretty sure it'd work the same

    • @olatrials
      @olatrials 6 лет назад +1

      No, that does precisely the same as vals.fill(Math.random());

    • @He4vyD
      @He4vyD 6 лет назад

      What about vals.fill(Math.random) ?

    • @olatrials
      @olatrials 6 лет назад

      That would set all elements to be the function Math.random, which is probably not at all what you want.

  • @chunckyfreshnut
    @chunckyfreshnut 3 года назад

    if you use map on at object . It will change object, it act differently from a value. So you won't have to re assigned the value to itself

  • @grahamvp
    @grahamvp 2 года назад

    Just fabulous

  • @rahulmathew8713
    @rahulmathew8713 3 года назад

    Simple and to the point

  • @armandopenaleonett1258
    @armandopenaleonett1258 2 года назад

    You are the best thank you !

  • @khoanguyen3044
    @khoanguyen3044 6 лет назад

    love your energy

  • @Burbon211
    @Burbon211 5 лет назад

    Such a nice person :)

  • @diastrus1236
    @diastrus1236 5 лет назад

    How much coffee and energy drinks you drinking before these vids lol