I'm not sure about the map syntax.
I've tried to fetch the result score from the original object to be part of a new object.
filteredResults.push(currentResults
.map(({ item, result }) => ({
...item,
resultScore,
result: {
...result,
name:
!Array.isArray(result.name) ?
result.name
: result.name
.filter(({ '@language': lang }) => !negLanguagesParam.includes(lang))
}
}))
How do you read this syntax?
It doesn't follow the API syntax.
For each iteminCurrentResult modify ...
What does the ... mean, and how should I use this correctly?
How would you add the resultScore to be next the name in the new object?
Array of original objects:
And I wish it would turn into:
Update
I think these comments explain what I was looking for:
filteredResults.push(currentResults
.map(({ allOther, resultScore, result }) => ({
...allOther,
result: {
...result, //shallow copy the object
resultScore, //add new memebr1
name: //add new memebr2
!Array.isArray(result.name) ?
result.name
: result.name
.filter(({ '@language': lang }) => !negLanguagesParam.includes(lang)) //({}) for taking a specific named attribute
}
}))

