1

I logged the following:

console.log(io.nsps['/'].adapter.rooms[socket.room]);

and it returned the following:

Room { sockets: { '/#O6L2als5FU-VfHSoAAAA': true }, length: 1 }

How might I edit console.log so that it returns the length value? I tried .length, .sockets.length, I also added [1] to the end. These were all unsuccessful.

2 Answers 2

2

Since .length is reserved, it returned "Cannot read property 'length' of undefined". Using ["length"] fixed the issue.

Sign up to request clarification or add additional context in comments.

14 Comments

"Since .length is reserved" --- WAT
I agree David, but it's not mine to change. And to zerkms, I hope that I did not misuse the term 'reserved'.
@manbearpig1 uhm, there is nothing special about .length. You can freely assign a property with that name to your object. "Cannot read property 'length' of undefined" error message is about WHERE you read from not WHAT you read.
length is the key which has a value of 1 in this case, while .length is a method that evaluates the length of something.
.length and ['length'] are guaranteed by the standard to be evaluated in the same way. If you're using a JS engine that complies with the standard - there is no way to see any difference between how those are interpreted.
|
1

console.log(io.nsps['/'].adapter.rooms[socket.room].length); should work

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.