OneBite.Dev - Coding blog in a bite size

create an array of number in Go

Code snippet on how to create an array of number in Go

// Create a slice of numbers
arr := []int{1, 2, 3, 4, 5}

This code creates an array of numbers in Go. First the keyword “arr” is used for create a slice of numbers and the equals sign (=) is used to assign a list of numbers to the array. The list is surrounded by curly braces ({}) and contains five numbers, from 1 to 5. Finally, the two forward slashes (//) are used to add a comment. The comment explains what the code is doing, in this case creating an array of numbers.

go