// 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); } */
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.
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
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.
@@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.
@@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.
// 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);
}
*/
so these videos are made 1 month back and set on auto upload at specific time . nice of 🫵
index and array are built in functions to provide the index values and array collection of fruits and numbers..?
array[index] can also write “return” ??
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.
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.
make sure that you declared the function separately before implementing it in the function call
Hey it is just incredible how you can just explain these concepts in just 8 minutes! thanks so much for makeing these videos ! :)
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
i suggest u do it on paper.
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.
@@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.
@@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.
forEach also has thisArg option.
very concise, thanks bro
amazing explanation ! understood!
Love you bro ❤❤
Supereb
thank!! love that!
Great video 👍 thank you 😊
thanks bro :)
❤❤❤