📅  最后修改于: 2023-12-03 15:14:42.691000             🧑  作者: Mango
Disemvowel JavaScript is a function that removes all vowels (a, e, i, o, u) from a given string in JavaScript. This function is often used in text processing applications, where it is necessary to remove certain characters from a string.
function disemvowel(str) {
return str.replace(/[aeiou]/gi, '');
}
The disemvowel
function takes a string as an argument and returns a new string with all vowels removed. This is achieved using the replace
method, which takes two arguments: a regular expression pattern and a replacement string.
The regular expression pattern /[aeiou]/gi
matches all vowels (case-insensitive) in the input string. The g
flag specifies a global search and the i
flag specifies a case-insensitive search.
The replacement string ''
is an empty string, which effectively removes all matches from the input string.
const inputString = "Hello World!";
const outputString = disemvowel(inputString);
console.log(outputString); // "Hll Wrld!"
In this example, the input string "Hello World!" is passed to the disemvowel
function, which returns a new string with all vowels removed. The output string "Hll Wrld!" is then logged to the console.