• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • Home
  • Learn to Code
    • Python
    • JavaScript
  • Code Snippets
    • HTML
    • JavaScript
    • jQuery
    • PHP
    • Python
    • SAS
    • Ruby
  • About
You are here: Home / JavaScript / Remove Vowels From String In JavaScript

Remove Vowels From String In JavaScript

May 9, 2022 Leave a Comment

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.

Other Articles You'll Also Like:

  • 1.  Using JavaScript to Calculate Average of Array of Numbers
  • 2.  Using JavaScript to Get the Host URL
  • 3.  How to Change an Image on Hover Using JavaScript
  • 4.  How to Find the Longest String in an Array in JavaScript
  • 5.  Creating a JavaScript Function to Subtract Two Numbers
  • 6.  Remove Parentheses From String Using JavaScript
  • 7.  JavaScript asinh – Find Hyperbolic Arcsine of Number Using Math.asinh()
  • 8.  How to Use JavaScript to Round Up Numbers
  • 9.  Using JavaScript to Get a Random Number Between 1 and 20
  • 10.  JavaScript If Not – Check if a Condition is False

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2023 · The Programming Expert · About · Privacy Policy