Im trying to push data to the browser. How to get the JSON to a Javascript array? Which I can then use for selecting the first key-value or sorting the object.
Here's the code in the browser/client side:
socket.on('notification', function (data) {
$.each(data.users,function(index,user) {
usersList = user.Bob // How to select unknown value/key? Example user[0]
});
$('#koersgroot').html(usersList);
});
Here's the JSON format
{
"users": [
{
"Bob": 1,
"Alice": 2,
"Carol": 3
}
]
}
JSON.parse/stringify.. but I suspect that it (i.e. "JSON") is not related to the problem."users":part of the socket message? Also, what socket library are you using?datavariable", or "How to select unknown value/key?"