Sometimes, we want to get the second digit from a number with JavaScript.
In this article, we’ll look at how to get the second digit from a number with JavaScript.
How to get the second digit from a number with JavaScript?
To get the second digit from a number with JavaScript, we convert it to a string and destructure it.
For instance, we write
const [, digit] = myVar.toString();
to call myVar.toString
to return a string version of the myVar
number.
Then we get the 2nd digit
with `destructuring.
Conclusion
To get the second digit from a number with JavaScript, we convert it to a string and destructure it.