When using range
and a dictionary, I always seem to get results in a case-sensitive sort by key. An answer on StackOverflow seems to indicate that go iterates maps in a random order. Is there a method to make range
return dictionary elements in their original, unsorted order?
{{- $map_test := dict
"Key 99" "Value 99"
"Key 2" "Value 2"
"Key 1" "Value 1"
"Key 3" "Value 3"
"key 1" "Value 1 (lowercase)"
-}}
{{ range $key, $value := $map_test }}
<li>{{ $key }}: {{ $value }}</li>
{{ end }}
The above returns:
- Key 1: Value 1
- Key 2: Value 2
- Key 3: Value 3
- Key 99: Value 99
- key 1: Value 1 (lowercase)