title case javascript
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 Lincoln
Also in JavaScript:
- angular current year
- append before jquery
- javascript set file input value to null
- nodejs oauth2 request
- Math.random javascript double
- promise catch javascript
- how to remove 000webhost watermark 2019
- how to run mocha tests on asynchronous functions in script
- http requests in vue 3
- node list files in directory
- jquery add class
- p5 js lines
- concat array javascript
- how to make an if statement in javascript
- same file select angular second time not selected
- postmark with nodejs
- javasript array indexof
- sort an array by the laster letter of element javascript
- javascript filter array by groups of highest
- discord js stats command
- es6 compare two arrays
- turn Iterator into array JS
- curl what is --data
- js remove if