-1
I have two arrays:
Exam:
[
{
"id": 1,
"title": "Avaliação - Procedimento em Serras",
"description": "Uma pequena descrição sobre a avaliação."
},
{
"id": 3,
"title": "Avaliação de Recuperação - Procedimento em Serras",
"description": "Uma pequena descrição sobre a avaliação."
}
]
exam_score:
[
{
"id": 4,
"score": "0.00",
"exam_id": 1
}
]
I need to get to the field exam_id
array exam_score
is equal to some field id
array exam
. If equal, add the field score
in the array merged (down below)
const merged = exams.map((e) => ({
...e,
exam_score: { ...exam_score.some(({ exam_id }) => exam_id === e.id) },
}));
However, I am getting the following error:
"message": "Converting circular Structure to JSON n --> Starting at Object with constructor
Is this the right way to perform this operation? What is wrong?
You are using
some
Why? Wouldn’t it be afilter
?some
returns onlytrue/false
.– Cmte Cardeal
Né.. Some returns a boolean value. Thank you very much!
– Fred
add the score field to the merged array using
some
Voce will only return a boolean, will not merge.– Cmte Cardeal
The code that’s in the question nay generates the error "Converting circular Structure to JSON" (see), then the problem is in another part of the code that was not shown. Please [Edit] the question by placing a [mcve] that reproduces the problem.
– hkotsubo
Anyway, it is not clear what the result should be. Vc says that the score should be added to the array
merged
, then what would that look like? Would that be https://ideone.com/5zgUrU ?– hkotsubo