I am dealing with a JSON object that looks like this:
var server = [{
name: 'xVg1',
players: ['foo', 'bar','player1'],
status: "on",
origin:"",
}, {
name: 'xVg2',
players: ['foo1', 'bar1','player2'],
status: "off",
origin:"",
}, {
name: 'xVg3',
players: ['foo2', 'bar2','player3'],
status: "on",
origin:""
}];
My goal is to efficiently extract all the player names into a single array from this object. I want the result to look like this:
player=['foo', 'bar','player1','foo1', 'bar1','player2','foo2', 'bar2','player3']
I attempted to achieve this using a forEach loop, but it resulted in an array of arrays rather than a single array like the desired output shown above.
var arr=[]
server.forEach(val =>{
arr.push(val.players)
})