To remove vowels from a string in JavaScript, the easiest way to do this is to use the JavaScript String replace() method with a regex expression.

someString.replace(/[aeiou]/g, "");

Let’s see this in a full example using text from our About page.


var someString = "This blog is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes."

someString = someString.replace(/[aeiou]/g, "");

console.log(someString);

#Output:
Ths blg s cmpltn f prgrmmr’s fndngs n th wrld f sftwr dvlpmnt, wbst crtn, nd tmtn f prcsss.

Let’s take a look at another example.


One thing about the code we used above, is that it is case-sensitive. Let’s say we use the code on the following sentence with capital letters added, and see the results:


var someString = "This blog is A compilation of a programmer’s findings in the WORLD of software development, WEBSITE creation, And automation Of processes."

someString = someString.replace(/[aeiou]/g, "");

console.log(someString);

#Output:
Ths blg s A cmpltn f prgrmmr’s fndngs n th WORLD f sftwr dvlpmnt, WEBSITE crtn, And tmtn Of prcsss.

As you can see the, only the lower case vowels were removed from the sentence. If we want to remove all vowels, regardless of case like we did in our first example, we would use the following code:


var someString = "This blog is A compilation of a programmer’s findings in the WORLD of software development, WEBSITE creation, And automation Of processes."

someString = someString.replace(/[aeiouAEIOU]/g, "");

console.log(someString);

#Output:
Ths blg s cmpltn f prgrmmr’s fndngs n th WRLD f sftwr dvlpmnt, WBST crtn, nd tmtn f prcsss.

As you can see, we get a similar result to our first example in that all of the vowels have been removed.

There is one last thing we can do to make our code even shorter.

someString.replace(/[aeiou]/gi, "");

The i added after the g in the regex above will remove any case-sensitivity and remove all instances of the vowels.

Hopefully this article has been useful for you to learn how to remove vowels from a string in JavaScript.

Categorized in:

JavaScript,

Last Update: March 14, 2024

Tagged in: