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


Could someone explain me about the index

I understand its purpose, but what does it mean/ how is it used in arrays. (swift) Actually, could you just explain what the index is/ how it is used... in short, can someone just explain to me what the index is....

2 Answers

Hi Egor. Just to be clear - index without context is a very loose concept... There is no "the index" if not in a specific context.

Normally, however, "index" is used to describe a pointer to a specific spot/row/item/whatever in an ordered list. I am using very broad terms here... It could be a value in an array or a row in a table - as long as there can be many items in an ordered fashion you use an index to specify which item/row/etc you are interested in.

var array = ["First Item", "Second Item", "Third Item"]

The array above has three items and you can access each of them using an index. In all programming languages (that I am aware of) basic enumeration begins with index 0. So to get the first item you would say array[0], and to get the second array[1] etc. etc. Makes sense?

A index is a position in a array. Say you have a array of colors var colorsArray = ["red", "blue", "gray", "orange"]

Okay now to get the index position for blue you need to call it like this println(colorsArray[1]) <----it's index 1 because index starts at 0 position

Hope this helps.