How can I find the index of an element within an array?
For example, given
my @weekdays = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
How could I find the index for 'Thursday'?
How can I find the index of an element within an array?
For example, given
my @weekdays = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
How could I find the index for 'Thursday'?
You can use first (or grep, if you want to know about all matches, not just the first one) with :k to return the key (which for a list is always an Integer index) instead of the value:
say @weekdays.first('Tuesday', :k); # 1