JavaScript forEach() method in 8 minutes! ➿

แชร์
ฝัง
  • เผยแพร่เมื่อ 30 ก.ย. 2024

ความคิดเห็น • 23

  • @BroCodez
    @BroCodez  ปีที่แล้ว +7

    // forEach() = method used to iterate over the elements
    // of an array and apply a specified function (callback)
    // to each element
    // array.forEach(callback)
    // element, index, array are provided
    // -------------- EXAMPLE 1 --------------
    const numbers = [1, 2, 3, 4, 5];
    numbers.forEach(cube);
    numbers.forEach(display);
    function double(element, index, array){
    array[index] = element * 2;
    }
    function triple(element, index, array){
    array[index] = element * 3;
    }
    function square(element, index, array){
    array[index] = Math.pow(element, 2);
    }
    function cube(element, index, array){
    array[index] = Math.pow(element, 3);
    }
    function display(element){
    console.log(element);
    }
    // -------------- EXAMPLE 2 --------------
    let fruits = ["apple", "orange", "banana", "coconut"];
    fruits.forEach(capitalize);
    fruits.forEach(display);
    function upperCase(element, index, array){
    array[index] = element.toUpperCase();
    }
    function lowercase(element, index, array){
    array[index] = element.toLowerCase();
    }
    function capitalize(element, index, array){
    array[index] = element.charAt(0).toUpperCase() + element.slice(1);
    }
    /*
    function display(element){
    console.log(element);
    }
    */

    • @harshitpant07
      @harshitpant07 10 หลายเดือนก่อน +2

      so these videos are made 1 month back and set on auto upload at specific time . nice of 🫵

    • @BadavathBalaram
      @BadavathBalaram 9 หลายเดือนก่อน

      index and array are built in functions to provide the index values and array collection of fruits and numbers..?

    • @Nagira-j2f
      @Nagira-j2f 5 หลายเดือนก่อน

      array[index] can also write “return” ??

  • @piotrmazgaj
    @piotrmazgaj หลายเดือนก่อน +4

    This is my seal. I have watched the entire video, understood it, and I can explain it in my own words, thus I have gained knowledge. This is my seal.

  • @Suraj-zg5qc
    @Suraj-zg5qc หลายเดือนก่อน +1

    When I write .forEach(double) after the calling function ". forEach(display)" it shows origanl array of 1,2,3,4. Can you explain why sequence matters here. Thanks.

    • @saiprasanth614
      @saiprasanth614 23 วันที่ผ่านมา

      make sure that you declared the function separately before implementing it in the function call

  • @vctorroferz
    @vctorroferz 7 หลายเดือนก่อน +3

    Hey it is just incredible how you can just explain these concepts in just 8 minutes! thanks so much for makeing these videos ! :)

  • @UncannyPotato69
    @UncannyPotato69 9 หลายเดือนก่อน +4

    bro, i don't get what you mean when you say the element, index and array are already provided for? please help me understand what you mean by it. and thanks for making such cool tutorials

    • @Abdullah-ayab
      @Abdullah-ayab 8 หลายเดือนก่อน +1

      i suggest u do it on paper.

    • @wintalyrics1226
      @wintalyrics1226 7 หลายเดือนก่อน +5

      Array is an object, So it has properties and methods. So when we create an array variable it will have the properties and methods.
      Like it automatically counts the number of elements and assign it to the element property.

    • @natnaeltaye
      @natnaeltaye 6 หลายเดือนก่อน

      @@wintalyrics1226 hey yoo i like your explanation .
      i think your from ethiopia, i'm either so we can help each other out in this coding journey so if you down leave me your email or phone number.

    • @natnaeltaye
      @natnaeltaye 6 หลายเดือนก่อน

      @@wintalyrics1226 hey yoo i like your explanation.
      i think your from ethiopia, i'm either so we can help each other out in this coding journey if you down leave me your email or your phone number.

  • @TheProgrammingSensei
    @TheProgrammingSensei 6 หลายเดือนก่อน +3

    forEach also has thisArg option.

  • @hongquannguyen5532
    @hongquannguyen5532 9 หลายเดือนก่อน +3

    very concise, thanks bro

  • @mjylove2
    @mjylove2 6 หลายเดือนก่อน +1

    amazing explanation ! understood!

  • @gichuhisamuel4387
    @gichuhisamuel4387 10 หลายเดือนก่อน +1

    Love you bro ❤❤

  • @Stock632
    @Stock632 5 หลายเดือนก่อน +1

    Supereb

  • @yoroih
    @yoroih 7 หลายเดือนก่อน

    thank!! love that!

  • @khalidelgazzar
    @khalidelgazzar 8 หลายเดือนก่อน

    Great video 👍 thank you 😊

  • @dutdut11
    @dutdut11 9 หลายเดือนก่อน

    thanks bro :)

  • @gichuhisamuel4387
    @gichuhisamuel4387 10 หลายเดือนก่อน

    ❤❤❤