Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to split array from specific index swift 3? [duplicate]

For example I have an array of let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]. I want to get the value from index 5th to the last and the rest I want to throw it away. Any idea of this? Thank you in advance.

like image 582
EK Chhuon Avatar asked Nov 28 '22 00:11

EK Chhuon


1 Answers

This is what you are looking for:

arr[5..<arr.count]

It will print [6, 7, 8, 9, 10, 11, 12]. Adjust your index accordingly if you need it to start from a different index. Also make sure you check arr has more than 5 elements.

if you need to get this as an array try this Array(arr[5..<arr.count])

like image 51
adev Avatar answered Dec 31 '22 04:12

adev