I have a case where I want to insert two commas after every two digits instead of the last three digits I want to add one comma. The result will look like this ( 34,34,54,388 ). Could someone please help me with how to resolve this issue?
Code
export const newPriceFormatConverter = ([...x]) => {
let i = 2,
subStrings = []
while (x.length) {
subStrings.push(x.splice(0, i).join(''))
i+=2
}
return subStrings.join(',')
}
You could replace with positive lookahead of wanted groups.