Try this,
var numbers = "1,2,3,4,5,6,7,8,9,10";
var n=numbers.split(','),
i=0;
$('#button').on('click', function(){
$('#show').text(n[i++]);
if(i==n.length) i=0;
});
HTML
<div id="show"></div>
<button id="button">Increment me</button>
var numbers = "1,2,3,4,5,6,7,8,9,10";
var n = numbers.split(','),
i = 0;
$('#button').on('click', function() {
$('#show').text(n[i++]);
if(i==n.length) i=0;
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="show"></div>
<button id="button">Increment me</button>
If you want it on canvas then try it like,
Jquery
var numbers = "1,2,3,4,5,6,7,8,9,10";
var n=numbers.split(','),
i=0;
var canvas=document.getElementById("myCanvas");
var ctx=canvas.getContext("2d");
ctx.font="18px Arial";
$('#button').on('click', function(){
ctx.clearRect(0,0,300,300);
ctx.fillText(n[i++],20,20);
});
HTML
<canvas id="myCanvas" width="200" height="100"
style="border:1px solid #000000;">
Your browser does not support the HTML5 canvas tag.
</canvas>
<button id="button">Increment me</button>
Hope, this helps,
var indexLetter=0;
function paintletter(retryletter) {
var chars = charscontainer.innerHTML.split('');
// comment the blow code
/*letter = retryletter ||
chars[parseInt(Math.random() * chars.length,10)]; */
// add the below code
letter = retryletter ||
chars[indexLetter++];
if(indexLetter==chars.length) indexLetter=0;
c.width = container.offsetWidth;
......
Demo