var str = '123456789'; function division(str){ var arr = str.split(''), len = arr.length, i = 3; while(i < len){ arr.splice(len-i,0,','); i+=3; } return arr.join(''); } console.log(division(str)); //控制台输出:123,456,789
有什么错误的地方,欢迎大家积极拍砖!