Learn Go: Arrays
Learn to organize your data into arrays in Go!
StartKey Concepts
Review core concepts you need to learn to master this subject
Go Arrays
Empty Arrays
Array Creation
Access Array Values
Modify Array Values
Array Length
Arrays and Slices
Array and Slice Capacity
Go Arrays
Go Arrays
In Go, an array is a fixed size ordered list of elements with the same data type. Arrays are useful for collecting and accessing multiple related values. Example use cases include:
- Storing sensor values - Computing averages - Holding lists of information
Arrays and Slices
Lesson 1 of 1
- 1Imagine we are creating an online gaming platform, and need to keep track of players’ scores. For each player, we’d need to store their score at a consistent index for that player. This is a situat…
- 2To use arrays in our programs, we must first declare and name them. In Go, there are a variety of ways in which we can declare an array. In the next few exercises, we will explore methods of array …
- 3While empty arrays are useful, so are arrays already populated with elements! Sometimes we already know which values we are going to put in our array. Imagine we are doing some math homework, and …
- 4We’ve learned how to create arrays that contain values. But how can we access the values stored in arrays? While having a list of numbers in a program might look nice, we need to access values to …
- 5Being able to retrieve the values stored in our array is super helpful, but what if we need to change them? Changing an array value is something that happens all the time in professional programs. …
- 6So far we’ve been using arrays, which have a fixed size. If we were to want to store a different number of elements in our array, we’d have to make a whole new one. However, Go provides us with a u…
- 7Why might we need to find the length of an array? Describe a scenario or scenarios in which this would be useful. ### len len is a function which returns the length of an array or slice passed in…
- 8So far we have covered what arrays and slices are, and how to work with them at a basic level. However, a big aspect of working with slices are that we can add elements and the slice will resize au…
- 9All of this array and slice functionality is useful, but we need to be able to use it outside of main. In this exercise, we will learn to define functions which allow us to repeat functionality usi…
What you'll create
Portfolio projects that showcase your new skills
How you'll master it
Stress-test your knowledge with quizzes that help commit syntax to memory