The first time the loop runs, there's no problem. The get's shown when the loop ends, and every other time the loop runs. The .checked property works fine, to my knowledge, there's just the error... Does someone know what to do about this? My background in javascript isn't that broad, and I'm still learning. Thanks you.
I have already tried .checked === true and
.checked == checked
...
In the code snippet below dishes is an array of radiobuttons.
for (i = 0; i <= dishes.length; i++) {
if (dishes[i].checked) {
switch (dishesClass) {
.........
}
}
}
I expect no error in the console, but there are multiple. Every time the loop ends, the console states the same error.
Uncaught TypeError: Cannot read property 'checked' of undefined
Cannot read property x of undefinedis the most asked question on SO 😂 Show us the current state ofdishesplease.<from<=i <= dishes.length->i < dishes.lengthLast element in the array isdishes[dishes.length - 1].