To check if an array is empty in Go, you can use the `len()` function to check the length of the array.
In this example,
numbers
with some elements.len()
function to check the length of the array.package main
import "fmt"
func main() {
numbers := [3]int{1, 2, 3}
isEmpty := len(numbers) == 0
fmt.Println("Array is empty:", isEmpty)
}
Array is empty: false
In this example,
emptyArray
with no elements.len()
function to check the length of the array.package main
import "fmt"
func main() {
var emptyArray [0]int
isEmpty := len(emptyArray) == 0
fmt.Println("Array is empty:", isEmpty)
}
Array is empty: true
In this tutorial, we learned How to check if an Array is Empty in Go language with well detailed examples.