Reputation: 2474
I am learning about nodejs + express + socketio. I am making live chat for customer. I have successfully get user list in Admin page. currently Admin page show all user sending message but I need to show only selected user message from user list.
In this case I need one array or object which have all details about chat session but in my case details are coming from different events so I confused how to push the value.
When I search about array and object I found Arrays have order, objects don't but the statement is confusing me. upto now I can use object but I could not felt any difference between object and array except syntax.
Here I put two questions
How to push the data uniformly from different events for example after triggering three events my object or array should like below
chat={"name":"Bilal","mail":"[email protected]","socketid":"asgd","to":"John","message":"Hello!","ip":"192.168.1.4","time":"timestamp"};
Upvotes: 0
Views: 158
Reputation: 687
Okay so first let me tell you there is a lot you still need to read up about nodejs and programming in general to start with this project or it will confuse you.
Coming back to your question, the distinction between array and object in terms of having order is that - In simple terms think of "having order" as being able to number the items and retrieve them using an index. This is possible with arrays but not with objects. For example you have an array a
and object o
, a[5]
will give you the 6th element of a but o[5] doesn't make any sense. An object just holds pieces together in no specific order.
IMHO its best to communicate between methods using objects especially in nodejs. You also have the flexibility to use other complex structures when working with objects.
Upvotes: 1