There are incoming objects, such as:

Object {pos: "test2" , tar : "1"} Object {pos: "test3" , tar : "2"} Object {pos: "test4" , tar : "3"} Object {pos: "test5" , tar : "4"} 

It is necessary to unite in one line, what would be test2, test3, test4, test5 How to do it right?

client:

 socket.on('infos', function (data) { console.log(data); }); 

server:

 tsRoom.send("clientlist", function(err, response){ if(err){ console.log(err) } else { response.forEach(function(response) { socket.emit('infos', { pos: response.names, tar: response.uid }); }); } }); 

Incoming response data to the loop:

 [ { uid: 1, names: 'test2', { uid: 2, names: 'test3', { uid: 3, names: 'test4', { uid: 4, names: 'test5' } ] 
  • The incoming response data is not very valid to put it mildly - Andrew Paramoshkin
  • one
    Your data has a strong lack of closing brackets "}". - Igor

1 answer 1

If I understood correctly: there is an array with objects, for example:

 var x = [{pos: "test2" , tar : "1"}, {pos: "test3" , tar : "2"}, {pos: "test4" , tar : "3"}, {pos: "test5" , tar : "4"}] 

To get an array of pos keys, you can lure this array

 var out = x.map(function(el) {return el.pos}) 

The output will be [test2, test3, test4, test5]