[Solved] How can I write a function that will format a camel cased string to have spaces?


You can use regex to split on capitals and then rejoin with space:

.split(/(?=[A-Z])/).join(' ')

let myStrings = ['myString','myTestString'];


function myFormat(string){
return string.split(/(?=[A-Z])/).join(' ');
}

console.log(myFormat(myStrings[0]));
console.log(myFormat(myStrings[1]));

solved How can I write a function that will format a camel cased string to have spaces?