JAVASCRIPT - finding vowels in a string

Hello, I am working on a project that takes a string variable as an input. Then we have to check that variable if it holds characters that are vowels and print them out first. After we have printed all vowels, if there were any, we print the remaining characters of that string. Every character should be printed on a new line. Thanks in advance for any responses.

The code:

var s = “javascript”;

var counter;
for(var i = 0; i < s.length - 1; i++){
counter++;

if (s.charAt(i) == “a” || s.charAt(i) == “e” || s.charAt(i) == “i” || s.charAt(i) == “o” || s.charAt(i) == “u”){

console.log(s.charAt(i));

} else if(s.charAt(i) == “b” || s.charAt(i) == “c” || s.charAt(i) == “d” || s.charAt(i) == “f” || s.charAt(i) == “g” || s.charAt(i) == “h” || s.charAt(i) == “j” || s.charAt(i) == “k” || s.charAt(i) == “l”
|| s.charAt(i) == “m” || s.charAt(i) == “n” || s.charAt(i) == “p” || s.charAt(i) == “q” || s.charAt(i) == “r” || s.charAt(i) == “s” || s.charAt(i) == “t” || s.charAt(i) == “v”
|| s.charAt(i) == “w” || s.charAt(i) == “x” || s.charAt(i) == “y” || s.charAt(i) == “z”){

var arrayOfCharacters = [];
arrayOfCharacters = s.charAt(i);

}

if(counter == s.length - 1){

    for(var j = 0; j < arrayOfCharacters.length - 1; j++){
   console.log(arrayOfCharacters[j]);
    }
   
}

Found a more elegant way to solve this:

for (var i in s.split(’’)) {

if ([‘a’, ‘e’, ‘i’, ‘o’, ‘u’].includes(s.split(’’)[i])) {

console.log(s.split(’’)[i]);

}

}

for (var i in s.split(’’)) {

if (!([‘a’, ‘e’, ‘i’, ‘o’, ‘u’].includes(s.split(’’)[i]))) {

console.log(s.split(’’)[i]);

}

}

Though I am still curious what was wrong with my code.

You didn’t tell us what is wrong with your code. How is it failing?