Mootools if possible some number how to explode each digit

if I had a number like 123 how could I, with mootools if possible, get the index of each number so I can have something like

var thenumber = 123;
var firstvar = thenumber.indexOf(0);
etc…

You can use basic JavaScript techniques to turn the number in to a string, break it apart in to an array of separate characters, and then use indexOf to find the position of a character from that array.


var thenumber = 123;
var arr = thenumber.toString().split(''); // ['1', '2', '3']
var firstvar = arr.indexOf(0) // -1 which means, not found in the array

Or, are you wanting something else? Are you wanting to retrieve each part of the number?

With an array, you can use push/pop, which works on the end of an array. You can also use unshift/shift to work with the start of the array


var thenumber = 123;
var arr = thenumber.toString().split(''); // ['1', '2', '3']
var firstvar = arr.shift(); // firstvar is '1' and arr is now ['2', '3']

thank you, the code bellow is what I was looking for


some_string.charAt(0);