You can use regex to add a space where there is a lowercase letter next to uppercase.
Something like that:
"LightPurple".replace(/([az])([AZ])/, '$1 $2')
UPDATE If you have more than two words, you need to use the g flag to match all of these.
"LightPurpleCar".replace(/([az])([AZ])/g, '$1 $2')
UPDATE 2 . If you are trying to separate words like CSVFile , you may need to use this regular expression instead:
"CSVFilesAreCool".replace(/([a-zA-Z])([AZ])([az])/g, '$1 $2$3')
Rocket hazmat
source share