Golang - Program to find the index of the element from the given slice Code Example

The code for Program to find the index of the element from the given slice

package main
 
import "fmt"
 
func main() {
    // Slice
    numbers := []int{10, 20, 30, 40, 70, 90, 80}
    fmt.Println("Slice:", numbers)
 
    var index int = 3
     
    // element at index 3 in the slice
    elem := numbers[index]
    fmt.Println("Element at index 3 is:", elem)
}

/*
Slice: [10 20 30 40 70 90 80]
Element at index 3 is: 40
*/
Code by IncludeHelp, on February 28, 2023 15:32

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.