Get Index From Array Swift

[Solved] Get Index From Array Swift | Swift - Code Explorer | yomemimo.com
Question : swift array index of where

Answered by : chris-so

let person1 = Person(name: "John")
let person2 = Person(name: "Sue")
let person3 = Person(name: "Maria")
let person4 = Person(name: "Loner")
let people = [person1, person2, person3]
let indexOfPerson1 = people.firstIndex{$0 === person1} // 0
let indexOfPerson2 = people.firstIndex{$0 === person2} // 1
let indexOfPerson3 = people.firstIndex{$0 === person3} // 2
let indexOfPerson4 = people.firstIndex{$0 === person4} // nil

Source : https://stackoverflow.com/questions/24028860/how-to-find-index-of-list-item-in-swift | Last Update : Wed, 29 Jun 22

Answers related to get index from array swift

Code Explorer Popular Question For Swift