I got an array with following data structure:
[
{
_id: 'dgPMHw3ivRSp3wyWe',
content: {
en: [{ content: 'foo', extended: 'bar' }, {...}],
it: [{ content: 'any', extended: 'thing' }, {...}]
},
order: 1,
parent: 'Dn59y87PGhkJXpaiZ'
},
{...}
]
I need to modify this array to get only string values for content by selecting the first element of a specific language.
So for the english language the result should be:
[
{
_id: 'dgPMHw3ivRSp3wyWe',
content: 'foo',
extended: bar,
order: 1,
parent: 'Dn59y87PGhkJXpaiZ'
}
]
I know I could get the string with
const language = 'en'
array.forEach(doc => {
console.log(doc.content[language][0].content)
console.log(doc.content[language][0].extended)
})
But how do I replace it to get my result?