Rearrange index, position in map as per requirement


(BONTHALA C S MANIDEEP) #1

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.


(Yamil Bracho) #2

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


(BONTHALA C S MANIDEEP) #3

Can u share me an example to solve my issue


(Yamil Bracho) #4

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


(BONTHALA C S MANIDEEP) #5

Thank you


(Yamil Bracho) #6

you’re welcome!!!:ok_hand:


(system) closed #7

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