25% off

Use code FUNCMAIN at checkout for 25% off all premium courses.

Get started →
Getting the Size of an Array or Slice in Go
Code Snippet

Getting the Size of an Array or Slice in Go

go

In this code snippet, we are going to look at how you can retrieve the length of a type in Go using the len function.

In this example, we define an a slice of type string which contains a number of famous scientists. Below this instantiation, we then call len(scientists) to retrieve the length of this slice which is then printed out for us.

Further Reading:

If you enjoyed this code snippet, you may appreciate some of the other content on the site: