I have a function to delete Elements of an array at a certain position. After executing I get the Error: Index out of range. I don't know why. My Code is marked with the Error at "if self.liked1[j].id == id.id{". Can someone help me. Thanks in advance.
func remove(id: datatype2){
for j in 0..<self.liked1.count{
if self.liked1[j].id == id.id{
self.liked1.remove(at: j)
let db = Firestore.firestore()
db.collection((Auth.auth().currentUser?.email)!).document(self.liked1[j].id).delete()
}
}
}