Answers for "capitalize one letter in a string javascript"

98

javascript capitalize string

//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
0

how to capitalize a letter based on an index in javascript

function capitalize(s,arr){
  s = s.split("");
  for(var i = 0; i < arr.length; i++){
    if (s[arr[i]] == null) { continue }
    s[arr[i]]=s[arr[i]].toUpperCase();  
  }
  s = s.join('');
  return s;
};
Posted by: Guest on June-29-2020

Code answers related to "capitalize one letter in a string javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language