Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript loop over the alphabet and return the vowels

function vowelsAndConsonants(s) {
//Create Array of vowels
   const vowels = ["a","e","i","o","u"];
//Convert String to Array
   const arr = s.split("");
//Empty vowels and cons array
   var vowelsFound = [];
   var cons = [];
//Push vowels and cons to their arrays
   for (var i in arr) {
     if (vowels.includes(arr[i])) {
        vowelsFound.push(arr[i]);
        } else {
            cons.push(arr[i]);
        }
   }
//ConsoleLog so that they in order and cons follows vowels on new lines
   console.log(vowelsFound.join('
') + '
' + cons.join('
'))
}
//Test, Exclude in copy
vowelsAndConsonants(javascriptloops); 
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #javascript #loop #alphabet #return #vowels
ADD COMMENT
Topic
Name
5+3 =