little forEach loop question

so the person i'm following to learn JS is working on local storage and want to store a color value but i don't want to go through something that i don't understand, can someone explain what what forEach(li) means?
6 Replies
ABK | Muneer
ABK | MuneerOP3y ago
ABK | Muneer
ABK | MuneerOP3y ago
by saying lis.forEach(li) what is that li refers to in the forEach loop ? each li inside the querySelector?
b1mind
b1mind3y ago
console.log(lis) or better console.dir(lis) selector all makes a NodeList (kinda like an array but different methods) I know this is not the question but that would be a great project to learn about Event Delegation on. Because what that code does is creates Event listeners for each li. https://javascript.info/event-delegation
ABK | Muneer
ABK | MuneerOP3y ago
interesting this is quite new thing to learn so i only can use the elemets inside the selection to use for the forEach loop it's not like other loops where we just define something and use it like the with other loops i just tried to put like a letter or something and it did indeed show error for the NodeList
Rägnar O'ock
Rägnar O'ock3y ago
you can use whatever you want in a forEach loop to be more precise, a the .forEach() method allows you to declare a function that will be run on each items in an array (or in this case, an array-like, a NodeList)
ABK | Muneer
ABK | MuneerOP3y ago
oh wait yah i just got error because i didn't change the other li to the new letter lol i will read this because it looks like it answer my question and more thank you both b1mind and Ragnar !
Want results from more Discord servers?
Add your server