I have an array in Ruby that has some duplicate elements. E.g.:
fruits = ["apples", "bananas", "apples", "grapes", "apples"]
When I do the following:
fruits.index("apples")
# returns 0
I only get the first occurrence of "apples" which is, in this case, fruits[0]. Is there a way that I can run something similar to the above code and get the indexes of the other occurrences of "apples"? If I can't run something similar to the above code, how else can I get the indexes of the duplicate elements?