replace() function parameters
Hi everyone,
I've been using this expression and it works great, think it was created by Ukramedia but I'm not sure. It adds points to long numbers between every group of three digits.
I have a vague idea how it works, but I would love a literal 'translation' from someone experienced. This is the expression:
num = value; function addCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
addCommas(num)
I focus particularly on the the part from ".replace" onward. I know the B has something to do with the (right-side) boundary of what follows behind it, a digit, and then there's a negation ("not followed by digit) and then the global replacement of something (must be the specific position between the three-digit groups) with a comma.
Very fuzzy summarized, as you can see. What exactly does this line of code sound like in sequential commands?
