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.
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])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With