function c(x) {
var ARR;
ARR = x.split("");
ARR[0]=ARR[0].toUpperCase();//<<< then you should also
//uppercase just
// the first char
return ARR.join("");
}
console.log(c("test string"));
there is also a css rule which do the trick...
css capitalize
same just for a whole sentence
<script>
function titlelize(s) {
var ARR,WORDS;
WORDS = s.split(" "); // separate sentencein words
WORDS[i]=WORDS[i].toLowerCase();//ensure all other will be lowercase
for (var i = 0; i < WORDS.length; i++) { //run over each word
ARR = WORDS[i].split(""); // split word in chars
ARR[0] = ARR[0].toUpperCase() //make first car uppercase
WORDS[i] = ARR.join(" "); //recreate word from char
}
return WORDS.join(" ") // recreate sentence
}
</script>