In to get the index number php:
foreach much as index => each{
//get index number from index
}
How can I get the index number in go?
{{ range .post }}
{{ // how can i get index number? }}
{{ .Id }}
{{ .Name}}
{{ end}}
The INDEX function returns a value or the reference to a value from within a table or range. There are two ways to use the INDEX function: If you want to return the value of a specified cell or array of cells, see Array form. If you want to return a reference to specified cells, see Reference form.
Note that we can index a range using the colon ( : ) operator.
text/template
Variables:
If a "range" action initializes a variable, the variable is set to the successive elements of the iteration. Also, a "range" may declare two variables, separated by a comma:
range $index, $element := pipeline
So in your example:
{{ range $i, $e := .post }}
Index: {{ $i }}
{{ .Id }}
{{ .Name}}
{{ end}}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With