My application utilizes a third-party library that returns the map in the following format:
public sids: Map<SocketId, Set<Room>> = new Map();
When I try to access it using the code below:
io.of("/").adapter.sids.forEach(function(value, key) {
console.log(key + ' = ' + value)
})
The output appears as follows:
qZq18yG3TkoBPXNTAAAC = [object Set]
84q_yQYKB7JjOPAIAAAD = [object Set]
Upon logging the entire map, I see this structure:
Map(2) {
'qZq18yG3TkoBPXNTAAAC' => Set(2) { 'qZq18yG3TkoBPXNTAAAC', 'demo' },
'84q_yQYKB7JjOPAIAAAD' => Set(2) { '84q_yQYKB7JjOPAIAAAD', 'demo' }
}
Now, my query lies in how to access the values within the [object Set]. I attempted to use JSON.stringify but it didn't yield any results.
After implementing the recommended code snippet like so:
io.of("/").adapter.sids.forEach((set,key)=> {
let demo = [...set]
console.log('Key:', key,' Set to array: ', [...set] , set);
});
I encountered unexpected results:
Key: UJ3HwAIsHTgE9qvrAAAB Set to array: [] Set(2) { 'UJ3HwAIsHTgE9qvrAAAB', 'demo' } Key: Kvlt-mtnrE5NxMykAAAD Set to array: [] Set(2) { 'Kvlt-mtnrE5NxMykAAAD', 'demo' }