I am trying to add comma after some character length but I am failed because my case is different . What I want to achieve I want to insert comma after character length like (1,23,433,4444,55555) upto. If for example character is ( 123 ) . Then I want to insert comma after 1 ( 1,23 ) . If characters is (123433) then I want to insert comma (1,23,433) . Could someone please help me how to resolve this issue .
Thanks
Code
Convert = (x) => {
x = x.toString()
var lastThree = x.substring(x.length - 2)
var otherNumbers = x.substring(0, x.length - 3)
if (otherNumbers != '') lastThree = ',' + lastThree
var res = otherNumbers.replace(/\B(?=(\d{2})+(?!\d))/g, ',') + lastThree
return res
}
122333444455555666666do you expect an output of1,22,333,4444,55555,666666