data = {
"test": {
"questions": [
{
"option1Id": "1001",
"option2Id": "1002",
"tags": [],
"_id": "60e57c069107a038085ae3a1",
"question": "what is the atomic number of oxygen?",
"option1": "5",
"option2": "6",
"option3": "7",
"option4": "8",
"explanation": "The atomic number of oxygen is 8 and the mass number of oxygen is 16.",
"level": "Easy",
"option3Id": "1003",
"option4Id": "1004"
}]
}
}
I want to achieve something like this:
[{ option1: '5', option1Id: '1001'},
{option2: '6', option2Id: '1002'},
{option3: '7', option3Id: '1003'},
{option4: '8', option4Id: '1004'}]
Right Now, I'm trying to separate option1Id, option2Id, option3Id, and option4Id from option1, option2, option3, option4.
This is what I've done until now:
data = {
test: {
questions: [
{
option1Id: '1001',
option2Id: '1002',
tags: [],
_id: '60e57c069107a038085ae3a1',
question: 'what is the atomic number of oxygen?',
option1: '5',
option2: '6',
option3: '7',
option4: '8',
explanation:
'The atomic number of oxygen is 8 and the mass number of oxygen is 16.',
level: 'Easy',
option3Id: '1003',
option4Id: '1004',
},
],
},
};
options = [];
// console.log(Object.keys(data.test.questions[0]))
entries = Object.entries(data.test.questions[0]);
for (let i = 0; i < entries.length; i++) {
// options.push(entries[i][0].filter(e => (e.length = 6) && (e.includes('option'))));
if (entries[i][0].includes('option')) options.push(entries[i]);
}
console.log(options, 'First Options');
for (let i = 0; i < options.length; i++) {
if (options[i][0].includes('Id')) options.splice(options[i], 1);
}
console.log(options, 'Second options');
As you can see, I can't seem to get rid of option3Id and option4Id. Is there any way I can do that? And after that how do I convert it into my desired form?