Writing and referencing Arrays

Andrew stein
Aug 27, 2017 · 2 min read

Writing and referencing arrays may seem like a daunting task to start, but once you get the hang of it you will realize that it is easier than it may seem.

Arrays are a group of strings or integers (or even other arrays!) that we can use to reference in our code.

For example,

array_1 = [1, 2, 3, 4]

You will see here that we have an array of integers defined by a variable array_1 (keep in mind when writing code that you always separate two words with an underscore).

Now that we have our array set up, we want to reference one of those numbers. Those integers in the array are called elements, and we can reference any of the integers in this array by referencing them in the order they are in (starting with zero, then 1 etc.).

For example,

array_1 = [1, 2, 3, 4]array_1[0]   => 1
array_1[1] => 2
array_1[2] => 3
array_1[3] => 4

Another type of array that we can use is an array of strings, for example,

pets = ["dog", "cat", "turtle"] 

Don’t forget, that we reference each element in the array by the order number in which they are in. So in this example…

pets = ["dog", "cat", "turtle"]pets[0]    => dog
pets[1] => cat
pets[2] => turtle

One thing to note about arrays is that not only are they good for keeping your code organized, once you learn about loops, creating and referencing arrays will be an excellent tool in creating micro-programs(obviously they wont look great but they work!)

By writing and referencing arrays you can greatly enhance your skills as a a blooming coder, and use this skill for more complex code.

A great tool to use when starting with arrays would be ruby-doc, heres the link to that https://ruby-doc.org/core-2.2.0/Array.html. Good luck on your journey to being a great coder!

)

Andrew stein

Written by

Software Engineer + Video game lover. Feel free to connect with me or talk about tech https://www.linkedin.com/in/andrew-stein-755b8b11a/

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade