How to turn a string to a number? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to turn a string to a number?

For example, when using a prompt to enter a number, how to turn the result to an integer to get an element of an array? Edit: I messed up a little. I also mean to make it accept numerical operators like sum it 1 and then search the element.

2nd Jan 2019, 11:26 AM
Ric2908
Ric2908 - avatar
1 Answer
0
In js, there is no need to convert, for example, "1" to 1 in order to select an element of the array; conversion takes place automatically. a = 1; arr [a]; or a = "1"; arr [a], no difference
2nd Jan 2019, 11:51 AM
Игорь Яковенко
Игорь Яковенко - avatar