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.
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 ?