I am wondering how to get all the indexes of a repeating letter in a string, like:
"bananas from bahamas"
i want to get all the indexes of "a". If i do str.indexOf("a"), i will only get the first "a" that is in the string.
Every time i attempt to check the index of that letter, i get 1.
I want:
str.indexOf("a") === 1
str.indexOf("a") === 3
str.indexOf("a") === 5
str.indexOf("a") === 14
str.indexOf("a") === 16
str.indexOf("a") === 18
EDIT: I will try to refrain from using loops. is there a solution in which i can do this without loops?
thx in advance