I want to use a variable as index of my associative array
var usersName = []; // Just defining
userName[socket.id] = socket.name; // socket.id is an alphanumeric string
I want to use that socket.id(string) as the custom index of usersName array, so I can get a list of all the users connected to the socket. The problem is the way I'm escaping the variable ( I guess).
I've tried this but didn't work:
usersName ['\''+socket.id+'\''] = socket.name;
This works in PHP but, I just can't get it to work in javascript
Thanks for the help.
{}, not[].userName[socket.id] = socket.name;will work just fine.userName[socket.id]sure "works" but not the way you expect. Don't use non-numerical keys with arrays, use plain objects instead. "The problem is the way I'm escaping the variable ( I guess)." What made you think there is a problem at all?socket.id(is auto generated for each user connected) if I do what you said. How can I obtain the value of each one ?