I'm trying to return the index of an element in an array if it is a vowel, I'm unsure as to why I am unable to return the index with my code as it stands, the mdn states that the filter method should be able to return the element, elements index, or the name of the array so I'm a bit confused as to why I'm not able to do what I want, would someone be able to help me or at least break down why I can't do this?
here is my code below as well as a screenshot of what is being returned. I appreciate the help in advance
function vowelIndices(word) {
let result = word.split('').filter((element, index) => {
if (element.toLowerCase() === 'a' ||
element.toLowerCase() === 'e' ||
element.toLowerCase() === 'i' ||
element.toLowerCase() === 'o' ||
element.toLowerCase() === 'u' ||
element.toLowerCase() === 'y') { return index + 1 }
})
console.log(result)
return result
}
vowelIndices("apple")