forEach method
i'm finding it difficult to understand this code snippet? could someone please tell me what the
slide
and index
do?
i tried to change the forEach method to a forLoop so i can understand it better, but i could not access the slide property.
this is my attempt to rewrite it in forLoop method:
for(index=0; index<slides.length; index++){
slide.style.transform =
translateX(${index * 500}px);
}
3 Replies
a foreach loop goes over an array. Inside the loop every item of that array will be temporarily be named as 'slide' and the index is the place of that item in the array, which you can refer too.
here a more detailed explanation: https://www.freecodecamp.org/news/javascript-foreach-how-to-loop-through-an-array-in-js/
in a regular for loop it would be
Unknown Userβ’3y ago
Message Not Public
Sign In & Join Server To View
preciate this a lot @MarkBoots
thank you @webcat || π§Άπ
you both helped a lot. preciate it