var x = 123456; while (x != 0) { console.log(x % 10); x = Math.floor(x / 10); }