+ 2
Adding Element in an array
Why is this showing NAN https://code.sololearn.com/WiqGYfvzomMk/?ref=app
3 Answers
+ 2
The reason your code returns NaN, is due to the if statement.
if (ab[i].innerText == ""){...} It reads...
...if the inner text of ab[i] is equal to an empty string, add that value to the variable count.
There is only one element of the table that is equal to an empty string, the first element. And using parseInt on an empty string returns NaN.
Try this: if (ab[i].innerText)
+ 1
replace the for in with for of
+ 1
ODLNT Thank you