How can I convert a string of numbers like for example '21354561321535613'
into digits and store them in an array?
Each digit should be turned into an integer element in the array, so the string '21354561321535613'
should result in:
[2, 1, 3, 5, 4, 5, 6, 1, 3, 2, 1, 5, 3, 5, 6, 1, 3]
You can easily turn a digit into an integer by subtracting the ordinal value of
'0'
. Do this in a loop and you have an integer for each digit: