Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get index number from range

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}}
like image 737
Edwin Widhiyanto Avatar asked Aug 29 '18 10:08

Edwin Widhiyanto


People also ask

Can you INDEX a range in Excel?

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.

Can you INDEX a range in Python?

Note that we can index a range using the colon ( : ) operator.


1 Answers

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}}
like image 62
icza Avatar answered Oct 02 '22 14:10

icza