User JS Object `groups` array not populated for several users

Thanks all

While on this particular instance the groups still remains empty (even with the api of the user instead of the current session), I was able to achieve this by checking on the group ID in the group_users which as well stores the same data, just not with name

I did use my original approach to get the data as this is “just” a snippet added in Discourse as a head script, no theme or plugin.
I couldn’t get the actual api to work, but the AJAX approach works just as fine for what I needed it.

Thanks again all for the inputs, specially @Lhc_fl whose approach led me to the right solution for my case.