My for loop always displays the entire array length whenever I console.log out #2888
Answered
by
krakxn
blaynejosh
asked this question in
Q&A
-
Hello guys, im in a bit of a fix. I'm taking a tut. from freecodecamp and the exercise is to create a chrome extension. however, whenever my for loop logic runs, and the extension displays the input value, the entire array elements gets displayed with any new input. Here's the code: let myLeads = []
const inputEl = document.getElementById("input-el")
const inputBtn = document.getElementById("input-btn")
const leadsEl = document.getElementById("leads")
inputBtn.addEventListener("click", function() {
myLeads.push(inputEl.value)
// console.log(myLeads)
for (let i = 0; i < myLeads.length; i++) {
leadsEl.innerHTML += "<li>" + myLeads[i] + "</li>"
const li = document.createElement("li")
}
}) Please help me with a way to stop this. Thank you |
Beta Was this translation helpful? Give feedback.
Answered by
krakxn
Sep 27, 2022
Replies: 1 comment 4 replies
-
@blaynejosh He later on resolves that issue w/ localStorage and a way to delete the entries. Keep following the course. Good luck! |
Beta Was this translation helpful? Give feedback.
4 replies
Answer selected by
alymurtazamemon
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@blaynejosh He later on resolves that issue w/ localStorage and a way to delete the entries. Keep following the course. Good luck!