node.js - Javascript loop on a object -



want loop on object find what's object name have socket id, , when it's found console.log it
code:

getusernamebysocketid: function(socketid) {     for(var user in users.obj) {         var u = users.obj[user];          if(u.socketid == socketid) {             return u.username;         }     } }, 

edit:

user.obj :
add elements user.obj function create new user:

users.obj[id] = new users.user({username: username, socketid: socketid}); 

and users.user contains :

user: function(data) {     this.username = data.username;     this.socketid = data.socketid; }, 


when call function , console.log it, return nothing.
how can solve ? thanks

finally i've found problem using @watte's users.obj empty


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -