[Solved] Javascript convert string to sentence case with certain exclusions [duplicate]

You can check if the indexOf the txt not 0 so it’s not first word, and create a list of excluded words and also check if this list includes the txt, then return the txt as it is. const lowerCaseList = [“of”, “and”] function toTitleCase(str) { return str.replace( /\p{L}+/gu, function(txt) { if (str.indexOf(txt) !== 0 … Read more