JavaScript forEach() method in 8 minutes! ➿

  Рет қаралды 19,100

Bro Code

Bro Code

Күн бұрын

00:00:00 introduction
00:00:18 example 1
00:03:58 example 2
00:07:37 conclusion
// 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);
}
*/

Пікірлер: 20
@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 6 ай бұрын
so these videos are made 1 month back and set on auto upload at specific time . nice of 🫵
@BadavathBalaram
@BadavathBalaram 4 ай бұрын
index and array are built in functions to provide the index values and array collection of fruits and numbers..?
@user-fp8od8er9g
@user-fp8od8er9g 28 күн бұрын
array[index] can also write “return” ??
@vctorroferz
@vctorroferz 3 ай бұрын
Hey it is just incredible how you can just explain these concepts in just 8 minutes! thanks so much for makeing these videos ! :)
@hongquannguyen5532
@hongquannguyen5532 4 ай бұрын
very concise, thanks bro
@mjylove2
@mjylove2 Ай бұрын
amazing explanation ! understood!
@yoroih
@yoroih 2 ай бұрын
thank!! love that!
@khalidelgazzar
@khalidelgazzar 3 ай бұрын
Great video 👍 thank you 😊
@gichuhisamuel4387
@gichuhisamuel4387 5 ай бұрын
Love you bro ❤❤
@dutdut11
@dutdut11 4 ай бұрын
thanks bro :)
@user-zp9no9jp2j
@user-zp9no9jp2j 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 4 ай бұрын
i suggest u do it on paper.
@wintalyrics1226
@wintalyrics1226 2 ай бұрын
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 Ай бұрын
@@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 Ай бұрын
@@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.
@gichuhisamuel4387
@gichuhisamuel4387 5 ай бұрын
❤❤❤
@TheProgrammingSensei
@TheProgrammingSensei 2 ай бұрын
forEach also has thisArg option.
@Stock632
@Stock632 Ай бұрын
Supereb
JavaScript map() method in 7 minutes! 🗺
7:01
Bro Code
Рет қаралды 19 М.
Learn JavaScript ARROW FUNCTIONS in 8 minutes! 🎯
8:02
Bro Code
Рет қаралды 17 М.
How To Choose Ramen Date Night 🍜
00:58
Jojo Sim
Рет қаралды 51 МЛН
Зу-зу Күлпәш. Агроном. (5-бөлім)
55:20
ASTANATV Movie
Рет қаралды 522 М.
8 Must Know JavaScript Array Methods
10:05
Web Dev Simplified
Рет қаралды 1 МЛН
3 Bad Python Habits To Avoid
10:40
Indently
Рет қаралды 43 М.
Learn JavaScript CALLBACKS in 7 minutes! 🤙
7:17
Bro Code
Рет қаралды 28 М.
Learn JavaScript Array Reduce In 10 Minutes
10:22
Web Dev Simplified
Рет қаралды 194 М.
JavaScript Pro Tips - Code This, NOT That
12:37
Fireship
Рет қаралды 2,5 МЛН
OpenAI SHOCKED Everyone! Voice, Vision, & Free?!
8:58
Theoretically Media
Рет қаралды 45 М.
JavaScript Loops Made Easy
10:52
codeSTACKr
Рет қаралды 163 М.
Where People Go When They Want to Hack You
34:40
CyberNews
Рет қаралды 184 М.
JavaScript reduce() method in 5 minutes! ♻
5:31
Bro Code
Рет қаралды 13 М.
How To Choose Ramen Date Night 🍜
00:58
Jojo Sim
Рет қаралды 51 МЛН