Find object value at index and store it in a different array using swift.
Can someone tell me the most optimized way for the following code snippet
var selectedIndex = [1,3,5]
var allData : [Person] = []
var ids: [Int] = []
for (index, item) in allData.enumerated() {
for id in selectedIndex {
if id == index {
ids.append(item.id)
}
}
}
ids = [allData[1].id,allData[3].id,allData[5].id]