Wednesday, 3 May 2017

How to only send part of an object from server to the client

Working on a chat program. When a user login his/her name is stored in var people = {}.

Then all names of online users, which is stored in 'people', are send to the client. Like this:

var people = {}; 

client.emit("update-people", {people: people});

Is it possible to only send part of the object: people? If so, how would that syntax be different from the one I have provided?

I thought that I might be able to do something like this: (but doesn't work)

client.emit("update-people", {people: people.client});

And vice versa, is it possible to remove a part of the object on disconnect?

I have heard some say that I should look in to JSON.stringify, but I am hoping that it is possible to just alter my code for what I am emitting.



via JonasSH

No comments:

Post a Comment