Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to count vowels in a string javascript

function vowelsCount(str){
    let count = 0;
    let vowels = ["a","e","i","o","u"];

    for(let letter of str.toLowerCase()){
        for(let v of vowels){
            if(letter===v){
                count++;
            }
        }
    }
    return count;
}
const string = "Hello World. I am a developer";
console.log(vowelsCount(string)); // outcome: 10
 
PREVIOUS NEXT
Tagged: #count #vowels #string #javascript
ADD COMMENT
Topic
Name
4+5 =