Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

capitalize first letter of every word javascript

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

// Example usage:

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

// Call the function:
const myStringInTitleCase = toTitleCase(myString);

Comment

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(); });
};
Comment

js capitalize word

const capitalizeFirstLetter(string) => 
	string.charAt(0).toUpperCase() + string.slice(1).toLowerCase()
Comment

javascript capitalize all letters

function capitalizeWords(string) {
   return string.replace(/(?:^|s)S/g, function(a) { return a.toUpperCase(); });
};
Comment

javascript capitalize all words

export function capitalize(str: string, all: boolean = false) {
  if (all)
    return str.split(' ').map(s => capitalize(s)).join(' ');
  return str.charAt(0).toUpperCase() + str.slice(1);
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: prop callback that changes parent state result in infinite render react js 
Javascript :: In React Router v6, activeStyle will be removed and you should use the function style to apply inline styles to either active or inactive NavLink components. 
Javascript :: Print Files with React 
Javascript :: how to use bootstrap in reactjs 
Javascript :: Angular generate by skipping test files 
Javascript :: react pass object to state 
Javascript :: handle stream javascript 
Javascript :: Perform native operation by javascript in Android 
Javascript :: html5 web component 
Javascript :: SHOPIFY STORE FRONT PASSWORD 
Javascript :: how to print message in nodjs 
Javascript :: child to perent data transfer in angular 
Javascript :: how to make your own version of filter method 
Javascript :: javascript synchronous and asynchronous list 
Javascript :: javascript random letters and numbers 
Javascript :: create a friend component react js 
Javascript :: Backbone Render And Initialize 
Javascript :: how to use file js 
Javascript :: random color javascript 
Javascript :: finding the smallest number other than 0 in an array javascript 
Javascript :: Class Has a Constructor Function 
Javascript :: jqxAngular 
Javascript :: tiled spatialmaterial godot 
Javascript :: vuejs router Cannot GET /about 
Javascript :: como contar los checkbox jquery 
Javascript :: Argument #1 ($client) must be of type AwsS3Client, AwsS3S3Client given 
Javascript :: react createelement data attribute 
Javascript :: prisma.db firebase 
Javascript :: jquery code convert into javascript online 
Javascript :: convert .js file to ts 
ADD CONTENT
Topic
Content
Source link
Name
8+3 =