var str = 123456;
var num = str.replace(/\B(?=(?:\d{3})+\b)/g, ',');
console.log(num);
如果str是數字需要 toString() 轉成字元串
效果: 123,456
轉載于:https://blog.51cto.com/jinliang/1612119
var str = 123456;
var num = str.replace(/\B(?=(?:\d{3})+\b)/g, ',');
console.log(num);
如果str是數字需要 toString() 轉成字元串
效果: 123,456
轉載于:https://blog.51cto.com/jinliang/1612119