Generate a comma-separated number by JavaScript one-liner
'1234567'.replace(/(\d)(?=(\d{3})+(?!\d))/g,
function() { return arguments[1] + ',' });
// => '1,234,567'
Written by Katsuya Hidaka
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Javascript
Authors
Related Tags
#javascript
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#