js数字转为数组

js yekong
var str = "123456789";
 
strCollection =  converStr(str).split(",");
 
function converStr(str){//给数字字符串添加逗号分隔符
    if(/\./.test(str)){
        return str.replace(/\d(?=(\d{1})+\.)/g, "$&,").split("").reverse().join("").replace(/\d(?=(\d{1})+\.)/g, "$&,").split("").reverse().join("");
    }else{
        return str.replace(/\d(?=(\d{1})+$)/g, "$&,");
    }
}
喜欢