javascript string proper case
function titleCase(str) {
return str
.split(' ')
.map((word) => word[0].toUpperCase() + word.slice(1).toLowerCase())
.join(' ');
}
console.log(titleCase("I'm a little tea pot")); // I'm A Little tea Pot
function titleCase(sentence) {
let sentence = string.toLowerCase().split(" ");
for (let i = 0; i < sentence.length; i++) {
sentence[i] = sentence[i][0].toUpperCase() + sentence[i].slice(1);
}
return sentence.join(" ");
}
function toTitles(s){ return s.replace(/\w\S*/g, function(t) { return t.charAt(0).toUpperCase() + t.substr(1).toLowerCase(); }); }
var str = toTitles('abraham lincoln'); // Abraham Lincolnfunction toTitleCase(str) {
return str.replace(
/\w\S*/g,
function(txt) {
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
}
);
}
// example
toTitleCase("the pains and gains of self study");
// "The Pains And Gains Of Self Study"
Also in JavaScript:
- js takes a string of words and returns the highest scoring word.
- vuejs use set to prevent duplicates
- pass variable to regrex literal notation javascript
- javascript json trypass
- anagram program in javascript
- remover o primeiro caracter de uma string javascript
- scroll down up js
- add new key value pair to object javascript
- jquery open page in new tab
- componentWillUnmount functional component for asynchronous requests
- discord js ban user
- how to wait for a function to finish in javascript
- js convert double to int
- angular input value
- firebase configuration on functions
- how to select the first div in jQuery
- adding dynamically add foreach elements as an array
- variables 2 python .Bartolome sintes Marco
- view background image in react native
- ModuleBuildError: Module build failed (from ./node_modules/sass-loader/lib/loader.js): Error: ENOENT: no such file or directory, scandir
- reactstrap search bar
- toggle element javascript
- node log centered
- check if number appears odd number of times in array javascript