Rearrange index, position in map as per requirement

Hi Team,

when ever i return map data. Go is sorting it in ascending order. But i want to re-arrange those key, value pairs in the order which i would like to. Is there any solution to get such sort of output.

1 Like

Depend on OS, the hash algoritm is different, so the order used when print a map will change.
You can use package “sort” to get an ordered map according their keys

1 Like

Can u share me an example to solve my issue

1 Like

Here a good sample : https://yourbasic.org/golang/sort-map-keys-values/

2 Likes

Thank you

1 Like

you’re welcome!!!:ok_hand:

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.