Answers for "swift get first n elements of array"

0

swift get first n elements of array

// 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
Posted by: Guest on July-05-2021

Code answers related to "swift get first n elements of array"

Code answers related to "Swift"

Browse Popular Code Answers by Language