Course: Learning GO

A collection of go basic fundamentals, syntax and concepts.

Table of contents

Lesson: Arrays

Collections

  • Arrays: fixed length - [5]int

  • Slices: similar to a dynamic length array, but they are actually chucks of arrays - []int

  • Maps: key/value dictinaries
    var VAR_NAME map[TYPE_0F_KEY]TYPE_OF_VALUE

    var Codes map[int]string
    
    // To get length
    qty := len(Codes)
    

You can have more that on function named init()

  • Collections are not objects, so we use global functions to work with them,
    such as len() or cap()

1 - Arrays:
The length of an array is fixed and needs to be defined during variable declaration.

// var VAR_NAME [LENGTH]TYPE
var scores [5]int

// Assign values
scores[0] = 20
scores[1] = 55

// Declare and initialize
goals := [5]int{3, 2, 6, 4, 3}