
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Number of Vowels within an Array in JavaScript
We are required to write a JavaScript function that takes in an array of strings, (they may be a single character or greater than that). Our function should simply count all the vowels contained in the array.
Example
Let us write the code −
const arr = ['Amy','Dolly','Jason','Madison','Patricia']; const countVowels = (arr = []) => { const legend = 'aeiou'; const isVowel = c => legend.includes(c); let count = 0; arr.forEach(el => { for(let i = 0; i < el.length; i++){ if(isVowel(el[i])){ count++; }; }; }); return count; }; console.log(countVowels(arr));
Output
And the output in the console will be −
10
Advertisements