let moneyType = num => {
let arr = (num + "").split("")
arr.reverse()
for (let i = 0, len = arr.length-1; i < len; i++) {
if ((i + 1) % 3 === 0) {
arr[i] = "," + arr[i]
}
}
arr.reverse();
return arr.join("");
}
console.log(moneyType(123456789))
//简便方法
console.log((123465789100).toLocaleString())
tips
如果还不清楚或者想交个朋友的同学可以微信联系我:qq981145483(备注:csdn fe)