Below I added some details about the original data and the expected output also added the code I tried.
The original data I have
original_data = [
{
question_name: "What is this question for?",
description: "This is a description",
type: "Multi choice",
answers: [
{
option: "opt1",
score: 2,
},
{
option: "opt2",
score: 4,
},
{
option: "opt3",
score: 5,
},
],
},
];
expected Output
expected_output = {
Question: "What is this question for?",
Description: "This is a description",
Type: "Multi choice",
option: "opt1",
score: 2,
option1: "opt2",
score1: 4,
option2: "opt3",
score2: 5,
};
The Code I tried
const updated_qstnData = original_data.map((d) => {
const {
question_name,
description,
type,
answers,
} = d;
return {
Question: question_name,
Description: question_description,
Type: answer_type,
};
});
According to the code which I tried, I was able to create an object with a Question, Description, and Type but don't know how to pick the key/value from the answers array of objects and add them to the object (updated_qstnData) that I am creating
How do I spread out the answers key/value to my output object?
expected_output, you can't have 2 same keys at once in an object