How to use a Loop In Javascript

A simple loop can also be used to iterate over each character in the string and exclude vowels.

Example: Implementation to remove vowels from a String using iterative approach.

JavaScript
function removeVowels(str) {
    let result = '';
    for (let i = 0; i < str.length; i++) {
        if (!'aeiouAEIOU'.includes(str[i])) {
            result += str[i];
        }
    }
    return result;
}

let inputString = "Hey Geeks of w3wiki!";
let result = removeVowels(inputString);
console.log(result); 

Output
Hy Gks f GksfrGks!

Time Complexity: O(n), where n is the length of the string

Auxiliary Space: O(1)

JavaScript Program to Remove Vowels from a String

The task is to write a JavaScript program that takes a string as input and returns the same string with all vowels removed. This means any occurrence of ‘a’, ‘e’, ‘i’, ‘o’, ‘u’ (both uppercase and lowercase) should be eliminated from the string.

Given a string, remove the vowels from the string and print the string without vowels. 

Examples: 

Input : welcome to w3wiki
Output : wlcm t gksfrgks

Input : what is your name ?
Output : wht s yr nm ?

Similar Reads

Using Regular Expressions

Regular expressions provide a concise and powerful way to manipulate strings in JavaScript. We can use the replace() method along with a regular expression to remove vowels from a string....

Using a Loop

A simple loop can also be used to iterate over each character in the string and exclude vowels....

Using Array Methods

Another approach is to split the string into an array of characters, filter out the vowels, and then join the remaining characters back into a string....