My new course Building a Production-Ready Service in Go is almost complete - try it out and let me know what you think!

Getting the Size of an Array or Slice in Go Image Getting the Size of an Array or Slice in 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: