How to replace all the dots in a number with JavaScript?

Sometimes, we want to replace all the dots in a number with JavaScript.

In this article, we’ll look at how to replace all the dots in a number with JavaScript.

How to replace all the dots in a number with JavaScript?

To replace all the dots in a number with JavaScript, we can use the string replace method.

For instance, we write:

const value = '8.30'
const newValue = value.replace(/./g, 'x');
console.log(newValue)

to call replace with a regex that matches all dots in the value string.

And we replace them all with 'x'.

Therefore, newValue is '8x30'.

Conclusion

To replace all the dots in a number with JavaScript, we can use the string replace method.