JavaScript
Result
Run
License
window.addEventListener("load", () => { document.body.textContent = thousandUnitSeparator("123456789"); }); function thousandUnitSeparator(str) { var arr = [...str]; arr.reverse(); var arr2 = []; arr.forEach((character, index, array) => { arr2.push(character); if ((index + 1) % 3 == 0 && array[index + 1]) { arr2.push(","); } }); arr2.reverse(); return arr2.join(""); }
Console
expand_less
License
License
by DevDic
Close