Question : swift get first n elements of array
Answered by : doge-amazedo
// the neatest way to get the first N elements of a Swift array is using
// prefix(_ maxLength: Int):
let someArray = [1, 2, 3, 4, 5, 6, 7]
let first5 = someArray.prefix(5) // 1, 2, 3, 4, 5
Source : https://stackoverflow.com/questions/28527797/how-to-return-first-5-objects-of-array-in-swift | Last Update : Mon, 12 Jul 21