remove all capital letters from a string in javascript

One way to remove all capital letters from a string in JavaScript is to use a regular expression to match and replace them with an empty string. Here's an example function:

index.tsx
function removeCapitalLetters(str) {
  return str.replace(/[A-Z]/g, '');
}
75 chars
4 lines

This function takes a string str and uses the replace() method with a regular expression to match all capital letters (using the character class [A-Z]) and the global flag g to match all occurrences, and replaces them with an empty string. The resulting string is returned.

Here's an example usage:

index.tsx
const myString = "Some Capital Letters Here";
const result = removeCapitalLetters(myString); // "ome apital etters ere"
120 chars
3 lines

Note that this method will remove all capital letters, including any that are part of words or acronyms.

gistlibby LogSnag