How to check if elements exist in an array with Go

1 Answer

0 votes
package main

import (
	"fmt"
	"slices"
)

func main() {
	arr := []int{1, 4, 8, 0, 15, 7, 100}

	if slices.Contains(arr, 8) {
		fmt.Println("exists")
	} else {
		fmt.Println("not exists")
	}
}


/*
run:

exists

*/

 



answered Oct 25, 2024 by avibootz
...