How to find the index of an element in a list (array) in Swift?
Hello! I just started learning Swift and encountered a seemingly simple task. I have an array of strings with usernames:
let users = ["Anna", "Boris", "Victor", "Galina", "Dmitry"]
I need to find the index of, for example, "Victor". I know that in other languages (like Python) there is a method index() that immediately returns the position of an element. But in Swift I can't find anything similar.
I tried writing a loop manually:
for i in 0..
This works, but it looks cumbersome. I think Swift should have a more elegant way. Especially since the array can be large, and such a loop is not the fastest. No answers yet.
Log in to leave an answer