xxxxxxxxxx
const days = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'];
let capitalize = days.map(day => day.charAt(0).toUpperCase() + day.slice(1).toLowerCase());
console.log(capitalize);
Run code snippet
xxxxxxxxxx
const lower = 'this is an entirely lowercase string';
const upper = lower.charAt(0).toUpperCase() + lower.substring(1);
xxxxxxxxxx
const string = "tHIS STRING'S CAPITALISATION WILL BE FIXED."
const string = string.charAt(0).toUpperCase() + string.slice(1)
xxxxxxxxxx
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
xxxxxxxxxx
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
xxxxxxxxxx
// this will only capitalize the first word
var name = prompt("What is your name");
firstLetterUpper = name.slice(0,1).toUpperCase();
alert("Hello " + firstLetterUpper + name.slice(1, name.length).toLowerCase());
xxxxxxxxxx
function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
console.log(capitalizeFirstLetter('foo')); // Foo
Run code snippet
xxxxxxxxxx
function capitalize(word) {
return word.charAt(0).toUpperCase() + word.toLocaleLowerCase().substring(1)
}
capitalize("bob");
xxxxxxxxxx
let val = ' this is test ';
val = val.trim();
val = val.charAt(0).toUpperCase() + val.slice(1);
console.log("Value => ", val);
xxxxxxxxxx
const days = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday'];
let capitalize = days.map(day => day.charAt(0).toUpperCase() + day.slice(1).toLowerCase());
console.log(capitalize);
Run code snippet
xxxxxxxxxx
const names = ["alice", "bob", "charlie", "danielle"]
// --> ["Alice", "Bob", "Charlie", "Danielle"]
//Just use some anonymous function and iterate through each of the elements in the array
//and take string as another array
let namescap = names.map((x)=>{
return x[0].toUpperCase()+x.slice(1)
})
console.log(namescap)