Array Iteration: 8 Methods - map, filter, reduce, some, every, find, findIndex, forEach

Поделиться
HTML-код
  • Опубликовано: 18 ноя 2024

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

  • @vinubox
    @vinubox 4 года назад +49

    The simplest, shortest and best array iteration tutorial ever

  • @GoatzAreEpic
    @GoatzAreEpic 5 лет назад +56

    1 month ago this looked like magic, now I can mostly grasp the ideas, not too fast but still progress y0l0

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

      I’m sure you’re a pro now!

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

      I'm expecting to hear that you now have atleast 2 YOE as a SWE

  • @ikhlasoyelami4164
    @ikhlasoyelami4164 4 года назад +7

    I paused this video in the last minute just to comment. Your tutorials are so amazing and straightforward. I dont know how to appreciate this better

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

    The simplest, shortest and best array iteration tutorial ever
    after 1 year trying finally i understand it , i can't believe

  • @yinandyang2599
    @yinandyang2599 2 года назад +1

    I was scratching my head trying to understand what sorcery are these methods doing. Your tutorial is the best thing I've come across on RUclips in some time thanks keep making these videos keep growing!!!

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

    Thank you for this tutorial, out of millions of tutorial on google, this is the simplest way of iteration I've ever understand... Thank you so much!!!

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

    Hi!! Just wanted to say that your videos are the best! Came to this one from the Javascript beginners video and both had helped me a lot. Everything you explain is so clear! Thank you very very much! And hope you can keep working on more videos!!

  • @warkentien2
    @warkentien2 7 лет назад

    Typo in the description, `sum` instead of `some`. Ironically what made me watch the video was a: "wait there's a method called sum? And here I was typing reduce((a,b)=>a+b)". I was glad to learn about `some, every, find and findIndex`.

    • @freecodecamp
      @freecodecamp  7 лет назад +2

      Fixed! Glad it got you to watch. 😃

  • @Hacking-NASSA-with-HTML
    @Hacking-NASSA-with-HTML 2 года назад

    The simple short and best array iteration explanation ❤👍 I will make an app for it!

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

    Best RUclips Channel to Learn coding I have ever watched !!!!!

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

    I've been looking everywhere for the .find function to actually work..and yours is the only one that worked and made complete sense....THANK YOU!

  • @009MAMAX
    @009MAMAX 7 лет назад +4

    This is cleared my life about array iterators, thx for the video!

  • @keithcorona5876
    @keithcorona5876 7 лет назад +5

    Very well done. I truly appreciate these videos alongside FCC's tutorials.

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

    Very simple and straightforward

  • @RedEyedJedi
    @RedEyedJedi 5 лет назад +3

    Absolutely excellent tutorial on these higher order functions. Thanks for making these videos.

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

    U r the best, this is the easiest explanation. I am learning JS now, so this is very very helpful.

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

    Thank you. Was having a difficult time with these but this was short, and clear and helped me understand.

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

    second time you helped me understand sth i was struggling with for hours

    • @Raul-fv8mi
      @Raul-fv8mi 5 лет назад +1

      Same! I was studying this type of code for hours and still didn't make complete sense. But this video made it very clear

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

      Same !

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

    simpler than the course am following . thanks

  • @randomdeveloper6456
    @randomdeveloper6456 7 лет назад

    Good short video to be used for future references purposes.

  • @levycapital-anasianintheus5282
    @levycapital-anasianintheus5282 6 лет назад +1

    Oh my God! Your lesson is awnsome. even my English is suck but this is so easy to understand for me. Thanks

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

    Thanks a lot! That saved a lot of our time

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

    Thanks for these clear examples!

  • @StrikesandSpares
    @StrikesandSpares 4 года назад +3

    "...so it's either all or nothing with this one."
    Relatable!

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

    Thank you for sharing these video's! Very clear explanation with simple examples.

  • @gohil_yajur
    @gohil_yajur 7 лет назад +4

    .reject() exactly opposite of .filter() || thank you for the video

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

      sounds good, except it doesnt exist in vanilla js

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

    Awesome! Best video i found on RUclips about this topic ;)

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

    People seem to have a hard time understanding that the functions map and filter return copies of the array with each element transformed element-wise by the callback function. Think about the difference between map and forEach and why you would use one over the other to solidify this. I'm going to start sending this video to anyone struggling with this.

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

    Thx for this great summary!

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

    Wow needed this!

  • @tylervoyer74
    @tylervoyer74 Год назад +4

    Pro tip: if you're looking for practice with arrow functions, take the codePen code and make all of them arrow functions. If you're taking notes, it saves space to write them as arrow functions, too.

    • @Wilton24
      @Wilton24 Год назад +2

      Yes! Arrow functions looks way cleaner and cooler,

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

    You did an awesome job, thank you. Put a smiling photo :)

  • @christopherkellett8738
    @christopherkellett8738 7 лет назад

    Thanks, great video and loved the quick pace of it.

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

    This video is nice, however it is good to mention that .find() will return the FIRST element that meets the condition only. It will not return all elements that meet the condition.

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

    Great Man. Short and Sweet.

  • @1998Sheldon
    @1998Sheldon 4 года назад +1

    I must say i normally never comment on videos but this one was truly amazing. Super straight and understandable.
    But where exactly is the difference between FIND and FILTER. For me FILTER is just the more versatil FIND am I right or am i missing something?

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

      Find method returns the found value in the array, if an element in the array satisfies the provided condition or undefined if not found.
      Filter method creates new array and add every element which satisfies the provided condition and after that returns the whole array. If there is no elements that satisfy the condition it returns empty array.

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

      The other comment is solid. It leaves out one tiny detail. Find will stop iterating early. If there are 10,000 elements and the third element meets requirements it stops iterating. This makes it faster than filter in most situations.

  • @AdityaRaj-lj5wf
    @AdityaRaj-lj5wf Год назад

    thanks man! this was crisp.

  • @mhabibullahhs5394
    @mhabibullahhs5394 2 года назад +1

    Believe me, this 6 minutes save my 6 hours.

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

    Thank you :)
    I will use my code for good.

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

    Honestly If you see his face turn serious
    It’s mean this Video is Worth watching for Sure😂❤️
    Im your bigFan Beau

  • @cookiecutter5162
    @cookiecutter5162 7 лет назад +3

    I'm not quite understanding the seemingly random nature of the function parameters... like in the last examples of 'find' where you put in item... are there a list of keywords that are tied to arrays in JS?

  • @JosephChambers
    @JosephChambers 7 лет назад +1

    .some() and .every() methods are cool. Thank you.

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

    Super helpful. Thank you

  • @Tromasssable
    @Tromasssable 7 лет назад +1

    Great short video!

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

    Thanks, this video is awesome!

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

    This guys is smooth

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

    Could this map explanation contain an error? Map doesn't return the result into the original array as it seems to be suggested here. Instead, map creates a new array and places the results in it. Which ends up having 2 arrays: three and double, respectively containing [1,2,3] and [2,4,6]. To verify this, simply add console.log(array) after console.log(double).

  • @metalheader1
    @metalheader1 7 лет назад +1

    This was an awesome video, thank you!

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

    short and nice

  • @izulien
    @izulien 7 лет назад

    Very helpful reminder!

  • @shaback2209
    @shaback2209 7 лет назад

    Very useful video !! I really learned something from you :)

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

    i love you i really need this kind of explanation

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

    reduce@ 2:29

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

    Variable names matter. For reduce when you have an accumulator you wouldn’t call it result. That’s not very descriptive. Accumulator is standard, or acc for short. But, for this purpose sum is most descriptive and brief.
    arr.reduce(sum, currNum) => sum + currNum);
    With reduce there is a default value provided. So, the 0 that you start with is implied and not needed.
    sum is a solid variable for a thing that sums. Result tells you it gets returned, but not what it is doing.
    currNum defines a variable as the current number. Element, or ele for short would technically be ok. But, those are too general. Num by itself would be perfectly fine.

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

    Thank you so much

  • @nishigaba777
    @nishigaba777 7 лет назад

    Very Nicely Explained (y)

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

    wow..that was so easy, u must be @ MIT

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

    Thank you

  • @Adam-gp3ij
    @Adam-gp3ij 4 года назад

    Very helpful

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

    HI, great tutorials. Howver, it seems i found a mistake, or maybe i dont understand. In all these cases, if you print the orignal array you start with, the values are not changed in that array. Howver, the value you use in the assignment, that becomes the new array wiht the values returned by the callback function. So forexampe in 2nd example, three retains [1,2,3] and doubled the value used in the assignment, becomes [2,4,6]

  • @mikhailbogovalov2330
    @mikhailbogovalov2330 10 месяцев назад

    Awesome!

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

    great explenation!

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

    Helpful video

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

    Thanks a lot man

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

    Using the filter function, is it possible to move items to another array when they are clicked? If yes, how is it done please?

  • @harai6063
    @harai6063 7 лет назад

    it was great explaination.

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

    Thanks soo much bro

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

    OMG. I didnt know about all these. Thanks! And also, I just realized I have been abusing map() when I should have done forEach() .. smh..
    does the => operator work for forEach as well btw?

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

      it's called arrow function and you can use it for any user defined functions. Just search on web...it's cool.

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

      Definitely spend time to learn about ES6 syntax. Since about 2017 it’s been the standard for how to write JavaScript. It’s called an arrow function or a fat arrow function. MDN has the explanation you want.

  • @joemw8806
    @joemw8806 4 года назад +8

    ... it "returns a new array"!! stop saying it put's elements back!!

  • @Zalmakiz
    @Zalmakiz 7 лет назад

    cool viedeo, just a question: why are the good olds "for (var i in array) {...}" and for (var i = 0;i < array.length;i++){...} missing? are they not good to use anymore?

    • @freecodecamp
      @freecodecamp  7 лет назад

      The videos are kind of out of order but will eventually be a complete JavaScript course that can be watched all the way through. Here is a video that is supposed to be before this one that covers for loops on arrays: ruclips.net/video/24Wpg6njlYI/видео.html

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

      This video covers array methods. In some cases these are cleaner than writing by hand. Array methods like this do get abused in some cases though.

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

    awesome

  • @awertyuiop2404
    @awertyuiop2404 7 лет назад

    thank you soooo much

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

    i guess where i get confused is when should i used map over foreach?

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

      Depends on what you’re going to do. ForEach is much more general. Map can only be used to perform actions on an array while returning an array. You don’t have to do anything with the array it returns.
      So, if you had an array of people and you want to run a greet function for each. Then, forEach would be preferred.
      guests.forEach(greet)
      If you did that with map you would waste the time and space to create an array that wasn’t used.

  • @HimanshuVerma-rr2ww
    @HimanshuVerma-rr2ww 5 лет назад

    Thank u..

  • @mohammedmokhtar2482
    @mohammedmokhtar2482 7 лет назад

    goo job ,i appreciate u

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

    map() returns a new array not modify the array itself

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

    Hey You must be teaching @MIT

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

    what do you mean by...... use your code for good............. ?

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

    findIndex @ 5:30

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

    find@ 4:42

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

    You kept saying the iterators replace the values in the original array, AND IT WAS DRIVING ME MAD!!!! You literally stored the iterated values in a new array. The original one remains unchanged!!!!

  • @pranto.cse25
    @pranto.cse25 Год назад

    joss awesome

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

    can some one help me plz , iam trying really hard to understand and learn javascript and i do understand what each method or function do but when iam trying to solve certain problem to make a thing i couldnt figure it out ( how to convert english words into code )so if anyone have recommendations or know what the problem with me and how to solve it , please reply to me as fast as you can and thanks in advance .

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

    hi can you make a video on recursion

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

      Done! ruclips.net/video/vPEJSJMg4jY/видео.html

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

    some@ 3:37

  • @yvng4697
    @yvng4697 2 года назад +1

    reduce was painful lol

    • @Cocoa-mania
      @Cocoa-mania 2 года назад +1

      I still don't understand reduce 😭. Understood the rest

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

      @@Cocoa-mania 1. forEach = loops through them.
      2. map = creates a new array from an array.
      3. filter = creates a new array based on condition.
      4. reduce = excutes a reducer function on each element of the array,
      resulting in a single output value.
      5. some = its like: does any item in the entire Array meet this condition?

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

      @@Cocoa-mania ruclips.net/video/s1XVfm5mIuU/видео.html watch this vid it may help u :)

    • @Cocoa-mania
      @Cocoa-mania 2 года назад

      Thank you very much. Clearer and I'll use this for reference

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

      @@Cocoa-mania anytime 🙏

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

    Your map terminology will hurt not help, map does not change, put back or replace.

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

    ['a','b','c'].forEach((item,index)=>{ console.log(item,index);});

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

    every@ 4:11

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

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

    This was way too quick of an explanation!

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

    While going through these, I made some notes to make it easier to understand. Feel free to grasp the ideas faster: codepen.io/adriancodestech/pen/GRQYZMb