Answers for "capitalize first letter of each word in a string array javascript"

4

javascript uppercase first character of each word

const uppercaseWords = str => str.replace(/^(.)|\s+(.)/g, c => c.toUpperCase());

// Example
uppercaseWords('hello world');      // 'Hello World'
Posted by: Guest on July-03-2020
1

capitalize first letter of every word javascript

text.replace(/(^\w|\s\w)/g, m => m.toUpperCase());
// Explanation:
// 
// ^\w : first character of the string
// | : or
// \s\w : first character after whitespace
// (^\w|\s\w) Capture the pattern.
// g Flag: Match all occurrences.

// Example usage:

// Create a reusable function:
const toTitleCase = str => str.replace(/(^\w|\s\w)/g, m => m.toUpperCase());

// Call the function:
const myStringInTitleCase = toTitleCase(myString);
Posted by: Guest on November-22-2021
1

Capitalize the first letter of string using JavaScript

function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
Posted by: Guest on January-04-2022

Code answers related to "capitalize first letter of each word in a string array javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language