Count the Number of Vowels in a String in JavaScript

This is a preview lesson
Register or sign in to take this lesson.

This tutorial shows how to get the count of number of vowels present in a string. In JavaScript, we can achieve this by using for loop and includes() method.

Example

const name = "ScanSkill";
const vowels = "aeiou"
let count = 0;

for (let i = 0; i < name.length ; i++) {
    if ( vowels.includes( name.charAt(i).toLowerCase() ) ) {
        count++;
    }
}

console.log("The number of vowels in word: ", name, " is: ", count);
Output
The number of vowels in word: ScanSkill is:  2