javascript - Replace nth word in sentence -


i have function string, i'm looking way format 3rd word (which number, want format comma). idea how it? should that:

function formatnumber(txt){     return txt.replace(3rd-word, formatnumber(3rd-word)); } 

match word consists of digits, , format it:

txt = txt.replace(/\b(\d+)\b/g, format); 

using formatting function, example:

function format(s) {   var r = '';   while (s.length > 3) {     r = ',' + s.substr(s.length - 3) + r;     s = s.substr(0, s.length - 3);   }   return s + r; } 

demo: http://jsfiddle.net/guffa/5ya62/


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -