How can i rotate array?
{
builds: [1, 2, 3]
}
{{ range $key, $value := $json.builds }}
<p>$value</p>
{{ end }}
^ returns
1, 2, 3
i want:
3, 2, 1
How can i rotate array?
{
builds: [1, 2, 3]
}
{{ range $key, $value := $json.builds }}
<p>$value</p>
{{ end }}
^ returns
1, 2, 3
i want:
3, 2, 1
come one this is a “computer scientist beginner state level” question (joking).
You have the length of your variable builds. (3 items).
You range through $key, $value
LENGTH - $key is the number of the item that is currently last, later on first
add it to a new array
after the range you should have the last item first and the first item last.
On the other side: there is a command sort range by sort descending instead of ascending through whatever is in your $json.builds array.
I mean “how to reverse array”, sorry
this discussion is duplicate.
original: Reverse Array