Array JavaScript NaN | Sololearn: Learn to code for FREE!
+ 1

Array JavaScript NaN

I have created an array and for the 14 value it shows NaN. Does anybody know why ?

1st Jun 2021, 12:30 PM
Gamer
Gamer - avatar
5 ответов
+ 4
Can you post that code sample of your try, to understand the problem fully..
1st Jun 2021, 12:42 PM
Jayakrishna 🇮🇳
+ 4
Gamer The value in the Array at index 14 is ' +"<br />"+"<br />" '. Adding + before a String form value , is converted to a Number . so it's converted equaling is "Not convertible to valid number ", so it saving as NaN -Not a Number ". that's why returning NaN. Remove + before it.
1st Jun 2021, 1:26 PM
Jayakrishna 🇮🇳
+ 3
In this case you use a prompt. Then you use the answer from the promt which is a string. Convert the string to a number and then you can use it.
1st Jun 2021, 2:45 PM
Leo
Leo - avatar
+ 1
Thank you very much. It worked 😄
1st Jun 2021, 3:38 PM
Gamer
Gamer - avatar
1st Jun 2021, 1:04 PM
Gamer
Gamer - avatar