Finding the vowel

function vowelIndices(word){
  var v = /[aeiouyAEIOUY]/g; 
  return word.split("").map((e, i) => v.test(e) ? (i+1) : 0).filter(e => e !=0)
}

var s = "supercalifragilisticexpialidocious"
console.log(s[24], vowelIndices(s)) // returns a [2,4,7,9,12,14,16,19,21,24,27,29,31,33]
                                                                 
//expected to return [ 2, 4, 7, 9, 12, 14, 16, 19, 21, 24, 25, 27, 29, 31, 32, 33 ]
// instead it returns   [2,4,7,9,12,14,16,19,21,24,27,29,31,33]

How come my code doesn’t catch the a in “alidocious” and the other vowels?

I think it’s because of the “g” flag. Have a read here.

yup it’s because of the global flag. Got rid of it and function worked perfectly as expected. Can’t seem to figure out why though, I’ll read through the link you sent. Thanks