javascript uppercase first character of each word
const uppercaseWords = str => str.replace(/^(.)|\s+(.)/g, c => c.toUpperCase());
// Example
uppercaseWords('hello world'); // 'Hello World'
javascript uppercase first character of each word
const uppercaseWords = str => str.replace(/^(.)|\s+(.)/g, c => c.toUpperCase());
// Example
uppercaseWords('hello world'); // 'Hello World'
javascript uppercase first letter of each word
const str = 'captain picard';
function capitalize(str) {
return str.charAt(0).toUpperCase() + str.slice(1);
}
const caps = str.split(' ').map(capitalize).join(' ');
caps; // 'Captain Picard'
javascript capitalize first letter of each word
function titleCase(str) {
var splitStr = str.toLowerCase().split(' ');
for (var i = 0; i < splitStr.length; i++) {
// You do not need to check if i is larger than splitStr length, as your for does that for you
// Assign it back to the array
splitStr[i] = splitStr[i].charAt(0).toUpperCase() + splitStr[i].substring(1);
}
// Directly return the joined string
return splitStr.join(' ');
}
document.write(titleCase("I'm a little tea pot"));
capitalize first letter in array of strings javascript
for(var i = 1 ; i < newArr.length ; i++){
newArr[i].charAt(0).toUpperCase();
capitalize first letter of each word javascript
const titleCase = function(text) {
let newText = '';
text = text.toLowerCase();
text = text.charAt(0).toUpperCase() + text.slice(1);
for (let i = 0; i < text.length; i++) {
if (text[i] === ' ') {
newText += ' ' + text[i+1].toUpperCase();
i++;
} else {
newText += text[i];
}
}
return newText;
}
how to capitalize first letter of word in javascript
function capitalizeFirstLetter(str, inAllWordsOfString = false) {
if (!inAllWordsOfString) {
//convert given string to lowercase
let lowerStr = str.toLowerCase();
// Now convert first character to upper case
let firstCharacter = str.charAt(0).toUpperCase();
// Now combine firstCharacter and lowerStr and return
return firstCharacter + lowerStr.slice(1);
} else {
let str1 = str.split(" ");
let returnStr = "";
for (let i = 0; i < str1.length; i++) {
let lowerStr = str1[i].toLowerCase();
returnStr =
returnStr + str1[i].charAt(0).toUpperCase() + lowerStr.slice(1) + " ";
}
return returnStr.trim();
}
}
capitalizeFirstLetter('hello word');
//output: Hello word
capitalizeFirstLetter('hello word', true);
//output : Hello Word
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us