Whale Talk - Need some help understanding a concept here

Hi, I don’t have any issues with the project instructions itself but i’m confused about how the code flows through the loop.
This is currently where I am at:

let input = 'Blue Whale Tie'; const vowels = ['a', 'e', 'i', 'o', 'u']; let resultArray = []; for(i=0; i< input.length; i++ ){ if (input[i] === 'e' ){ resultArray.push(input[i]); } for (j=0; j< vowels.length; j++ ){ if (input[i] === vowels[j]){ resultArray.push(input[i]); } } } console.log(resultArray)

The output for resultArray is
[
‘u’, ‘e’, ‘e’,
‘a’, ‘e’, ‘e’,
‘i’, ‘e’, ‘e’
]
The order of the output is what I am confused about. This is my logic for this: The outer loop goes through each index in the input variable and checks if it is equal to ‘e’, when it finds the match, it logs that value into resultArray so at this point, given that there are 3 e’s in the input (‘Blue Whale Tie’), then shouldn’t the resultArray be [‘e’,‘e’,‘e’] for now.
Then it enters the inner loop where it is matching the vowels with each letter in input. This should produce [‘u’,‘e’,‘a’,‘e’,‘i’,‘e’]. My understanding is that .push() appends the values to the end of the array so altogether, shouldn’t the output be:
[‘e’,‘e’,‘e’,‘u’,‘e’,‘a’,‘e’,‘i’,‘e’] and not
[
‘u’, ‘e’, ‘e’,
‘a’, ‘e’, ‘e’,
‘i’, ‘e’, ‘e’
]
? I know I am wrong obviously but can you explain why? Thank you

Please post a link to the exercise so everyone can read the narrative and the instructions.

Note that nested loops can show unexpected behavior until we wrap our head around their inner workings. It takes practice to get to this point.

Let’s examine the expected order, using a slightly more advanced method to arrive at it. Don’t be put off, and don’t use this solution, just examine the outcome:

s = "Blue Whale Tie"
v = {a: 'A', e: 'EE', i: 'I', o: 'O', u: 'U'} // object as lookup table
y = []
for (k of s) {
    if (k in v) {
        y.push(v[k])
    }
}
console.log(y.join(''))  //  UEEAEEIEE
// Blue Whale Tie
//   UE   A E  IE
//    E     E   E