This is my code, I want to create another filtered array like the example below, I have 2 arrays and want to add score information to it, I know it's simple but can't find the solution
const wishesData = [
{
name: "Peter",
presents: ["coffee", "holidays"]
},
{
name: "Mario",
presents: ["coffee", "videogames"]
},
{
name: "Amanda",
presents: ["computer", "tattoo"]
}
]
const scoresData= [
{
name: "Peter",
score: 10
},
{
name: "Mario",
score: 2.3
},
{
name: "Amanda",
score: 1.1
}
]
const result = wishesData.map((ele) => {
return {
...ele,
score: scoresData.find(s=> s.name === ele.name? s.score: 0)
}
})
console.log("este es el resultado=>",result)
I want to modify the array wishesData adding "score" to all objects inside and get to look like this example:
{
name: "Mario",
presents: ["coffee", "videogames"],
score: 2.3
}