JavaScript: How to access a character at a specific position in a number
Using JavaScript, You can access any character in a string:
'foo'[1]
//=> "o"
but, this doesn’t work with a number:
123[0]
//=> undefined
so you have to cast it to a string:
('' + 123)[0]
//=> "1"
and to cast back to a number again:
+('' + 123)[1]
//=> 2