JSFiddle - React, Tailwind, and code Playground
JavaScript
const data = {
"questions":[
{
"id":1,
"questionHeader":"Some question header",
"questionText":"Some question text?",
},
{
"id":2,
"questionHeader":"Some question header",
"questionText":"Some question text?",
},
],
"answers":[
{
"id":1,
"questionId":1,
"answer":"Some answer",
},
{
"id":2,
"questionId":1,
"answer":"Some answer",
},
{
"id":3,
"questionId":2,
"answer":"Some answer",
},
]
};
const newItem = data.questions.map((t1) => ({
...t1,
...data.answers.find((t2) => t2.questionId === t1.id),
}));
console.log(newItem);