I'm trying to convert an plain array into object with additional parameter
Lets say, I have an object
var obj = [{
index: 1,
question: "If a carrier wave of 1000 kHz is used to carry the signal, the length of transmitting antenna will be equal to _____ ?",
choices_list: ["300 m", "30 m", "3 m", "0.3 m"],
answer: "300 m",
explanation: "h = c/v = 3 × 10^8/10^6 = 300 m",
},{...}
{...}
{...}
...
...]
now With the help of below code I'll convert choices_list in to object
res_quiz_data.forEach(key => {
console.log(key.choices_list);
const map1 = key.choices_list.map(x => {
return { selected: false, choice: x }
});
console.log(map1);
})
Output
JS: [300 m, 30 m, 3 m, 0.3 m]
JS: [{
JS: "selected": false,
JS: "choice": "300 m"
JS: }, {
JS: "selected": false,
JS: "choice": "30 m"
JS: }, {
JS: "selected": false,
JS: "choice": "3 m"
JS: }, {
JS: "selected": false,
JS: "choice": "0.3 m"
JS: }]
now i need to way to modify the main Json object
Expected Output
var obj = [{
index: 1,
question: "If a carrier wave of 1000 kHz is used to carry the signal, the length of transmitting antenna will be equal to _____ ?",
choices_list: [{
"selected": false,
"choice": "300 m"
}, {
"selected": false,
"choice": "30 m"
}, {
"selected": false,
"choice": "3 m"
}, {
"selected": false,
"choice": "0.3 m"
}],
answer: "300 m",
explanation: "h = c/v = 3 × 10^8/10^6 = 300 m",
},
{....},
{....},
{....},
....
....]
const map1 = key.choices_list.map(x => {tokey.choices_list = key.choices_list.map(x => {