Today I Learned

A Hashrocket project

Ready to join Hashrocket? Find Openings here and apply today.

Get the first n items from a slice

Slices can take low and high bounds to determine which items to take.

mySlice[low bound : high bound]
package main

import "fmt"

func main() {
    numbers := []int{1,2,3,4,5,6,7,8}

    var s []int = numbers[0:3]
    fmt.Println(s)
}

=> [1 2 3]