Golang Code

Find the Length of an Array/Slice

· 51 words · 1 minute read #array #find #fmt #len #length

With Go, you can find the length of an array (or more accurately a slice) by using the internal len() function. Our example shows us creating a slice and then printing out it’s length.

package main

import "fmt"

func main() {
    array := []int{1, 2, 3, 4, 5}
    fmt.Printf("%d\n", len(array))
Image of Author Edd Turtle

Author: Edd Turtle

Edd is the Lead Developer at Hoowla, a prop-tech startup, where he spends much of his time working on production-ready Go and PHP code.

See something which isn't right? You can contribute to this page on GitHub or just let us know in the comments below. Thanks for reading!