Find the index of an item in an array

Hi,

I want to find the index of an item in an array. I need something like this:
Code Block Swift
let item = Item(title: "Test")
let index : Int = myArray.indexFor(item)
print(index)

Can you help me?
You can use this to get the index of a specific item:
Code Block Swift
let index = myArray.firstIndex(of: item)

If you want to find an item based on a condition use this:
Code Block Swift
let index = myArray.firstIndex(where: { item in
item.title.count < 5
})

Hi,
just to add to the answer

If you want to find an item based on a condition use this:

When using arrays that contain structs you can search for specific items like this:
Code Block swift
array.firstIndex(where: {$0.ID == reference})




Find the index of an item in an array
 
 
Q