Contains Value
Examples
Filter
console.log([1, 2, 3].includes(2));
console.log([1, 2, 3].includes(4));
console.log(['some', 'simple', 'words'].includes(123));
console.log(['some', 'simple', 'words'].includes('words'));
package main
import (
"fmt"
)
func Index(vs []string, t string) int {
for i, v := range vs {
if v == t {
return i
}
}
return -1
}
func Contains(vs []string, t string) bool {
return Index(vs, t) >= 0
}
func main() {
var strs = []string{"peach", "apple", "pear", "plum"}
fmt.Println(Contains(strs, "grape"))
}
Last Run
:
false