Go WASM question

106 views
Skip to first unread message

Tad Vizbaras

unread,
Oct 2, 2019, 8:45:34 AM10/2/19
to golang-nuts
I have sizable Go WASM application that creates map[string]interface{} and passes to JS or reads from JS library.
Go maps do not have predefined key order. But JS has object property order predictable in JavaScript objects since ES2015.

Problem: when JS objects are transferred from JS into Go and back they key order becomes scrambled.
At this point I have a small fix inside JS application that simply reorders keys coming from Go back into JS.
A bit of a hack but works.

Question: is there better solution?

My environment:
1. Go 1.13.
2. Chrome and Edge browsers.
3. Windows 10 desktop 64bits.

Leopoldo Caballero

unread,
Oct 3, 2019, 10:15:09 AM10/3/19
to golang-nuts
A map in Go is not ordered, so even the iteration is not the same between several iterations. You can see: https://blog.golang.org/go-maps-in-action
I suppose something similar occurs with objects in JS.

So, maybe you can iterate the map and output a slice and then sort the slice, that is maybe your currently approach.
Reply all
Reply to author
Forward
0 new messages