Answers for "Convert all the strings to title caps in a string array in js"

98

javascript capitalize words

//capitalize only the first letter of the string. 
function capitalizeFirstLetter(string) {
    return string.charAt(0).toUpperCase() + string.slice(1);
}
//capitalize all words of a string. 
function capitalizeWords(string) {
    return string.replace(/(?:^|\s)\S/g, function(a) { return a.toUpperCase(); });
};
Posted by: Guest on July-22-2019
30

javascript capitalize words

//Updated 
//capitalize only the first letter of the string. 
function capitalizeFirstLetter(string) {
    return string.charAt(0).toUpperCase() + string.slice(1);
}
//capitalize all words of a string. 
function capitalizeWords(string) {
    return string.replace(/(?:^|\s)\S/g, function(a) { return a.toUpperCase(); });
};
Posted by: Guest on December-12-2020
0

lowercase or uppercase all strings in array javascript

const names = ['Ali', 'Atta', 'Alex', 'John'];

const lowercased = names.map(name => name.toLowerCase());

console.log(lowercased);
// ['ali', 'atta', 'alex', 'john']

const uppercased = names.map(name => name.toUpperCase());

console.log(uppercased);
// ['ALI', 'ATTA', 'ALEX', 'JOHN']
Posted by: Guest on October-27-2021

Code answers related to "Convert all the strings to title caps in a string array in js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language