Gistlib Logo

gistlib

get second element in array in swift

main.swift
let arr = ["apple", "banana", "orange"]
let secondElement = arr[1] // Note that Swift uses zero-based indexing, so the second element is at index 1
print(secondElement) // Output: "banana"
189 chars
4 lines

similar swift code snippets

get second element in array in swift
sort an array in swift
remove an element from the end of an array in swift
add an element to the beginning of an array in swift
remove an element from the beginning of an array in swift
remove an element from the middle of an array in swift
find the index of an element in an array in swift
reverse an array in swift
add an element to the end of an array in swift
select a random element from an array in swift

related categories

swift
arrays
indexing

gistlibby LogSnag