I'm trying to grab the nested array called platforms, but i only want the first key in there. So for the Array it should be like [{platforms: [windows], [windows]]} instead of [{platforms: [windows, osx, linux, null], [windows, null, null, null]]} Is this even achievable? I looked through .map and .filter but can't seem to just grab the first piece of the array.
Example ARRAY
[{ id: 1,
game: { position: 1},
platforms: [ 'windows', 'osx', 'linux', null ],
title: 'xxx',
user: {
url: 'xxxx',
name: 'xxx',
id: 1
}
},{ id: 2,
game: { position: 2},
platforms: [ 'windows', null, null, null, ],
title: 'xxx',
user: {
url: 'xxxx',
name: 'xxx',
id: 2
}
]
How can I handle this in Javascript / NodeJS
var result = body.games.filter(a=>a).reduce((acc, a) => {
return acc.concat(a)
}, []).map(a=>a.platforms);
console.log(result);
Result =
[ 'windows', 'osx', 'linux' null ], [ 'windows', null, null, null ],