Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Swift 2.0 Collections and Control Flow Introduction to Collections Working with Arrays

jon kelson
jon kelson
5,149 Points

what would be the 1st item ?

hi I can do the code itself but! im confused what would the 1st item be ?

arrays.swift
// Enter your code below
var arrayOfInts = [1,2,3,4,5,6]
arrayOfInts.append(7)
arrayOfInts += [8]
let value = arrayOfInts[4]

1 Answer

Jhoan Arango
Jhoan Arango
14,575 Points

Hello:

In arrays, the items inside of the array, or elements, are organized by an index number starting with 0.

       // Index: 0,1,2,3,4,5,6,7,8, 9
let someArray = [1,2,3,4,5,6,7,8,9,10]

In this someArray we have Ints, which start from 1 and end in 10. The index of the first number, which in this case is the number 1, it's actually 0. The index of 2, is 1 . This might be a big confusing, so I will change the array to a different one.

let anotherArray = ["Blue","Black","Yellow","Green"]

In this array we have 4 items of type String. The first item is Blue which has an idex of 0, the Black has an index of 1, the Yellow has and index of 2 and so on.

Hopeful to have helped you.

And to answer your question. Your first item is 0.

Good luck