For example:
let word = 'Winter4000' const seperate = (word) => { ... } seperate(word) // output: Winter 4000
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
word.split(/([0-9.,]+)/).join(" ");
so it doesn’t put an extra space when it runs into a decimal point or comma.
Writing this as a function,
let word = 'Winter4,000.000'; const seperate = (input_word) => { return input_word.split(/([0-9.,]+)/).join(" "); } console.log(seperate(word));