Skip to content
Advertisement

(javascript) If you had a string that was a word with a number at the end. How would you add a space between the word and the number?

For example:

JavaScript

The word can be random and the number is always at the end.

Advertisement

Answer

Ian’s answer works for most integers, but for decimals or numbers with commas (like 1,000,000), you’ll want an expression like

JavaScript

so it doesn’t put an extra space when it runs into a decimal point or comma.

Writing this as a function,

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement