You can simply test when creating:
for (var i=1; i<=10; i++) { document.write(i); if (i<9) document.write(','); }
Note that when you start with an array, which may be your real question for the one you are asking, there is a convenient join function:
var arr = [1, 2, 3]; document.write(arr.join(','));
Denys seguret
source share