Help on push method with data from an API

So the below data is what I am fetching from an API... I'm trying to figure out how can I add the correct_answer property to the corresponding incorrect_answer property for each array of questions.

The result of all this should bring me back 5 arrays with the correct_answer and incorrect_answers combined into one array. Been stuck here feel like I'm close but no cigar. Thank you all for the help.

Keep in mind this Data will vary when it comes to the values but the keys will be the same.

Appreciate the help currently trying to build my first project being self taught and all

"results": [
  {
    "category": "Sports",
    "type": "multiple",
    "difficulty": "medium",
    "question": "What cricketing term denotes a batsman being dismissed with a score of zero?",
    "correct_answer": "Duck",
    "incorrect_answers": [
      "Bye",
      "Beamer",
      "Carry"
    ]
  },
  {
    "category": "Sports",
    "type": "multiple",
    "difficulty": "medium",
    "question": "How many scoring zones are there on a conventional dart board?",
    "correct_answer": "82",
    "incorrect_answers": [
      "62",
      "42",
      "102"
    ]
  },
  {
    "category": "Sports",
    "type": "multiple",
    "difficulty": "medium",
    "question": "Which car manufacturer won the 2016 24 Hours of Le Mans?",
    "correct_answer": "Porsche",
    "incorrect_answers": [
      "Toyota",
      "Audi",
      "Ferrari"
    ]
  },
  {
    "category": "Sports",
    "type": "multiple",
    "difficulty": "medium",
    "question": "What is the oldest team in the NFL?",
    "correct_answer": "Arizona Cardinals",
    "incorrect_answers": [
      "Chicago Bears",
      "Green Bay Packers",
      "New York Giants"
    ]
  },
  {
    "category": "Sports",
    "type": "multiple",
    "difficulty": "easy",
    "question": "Which country will host the 2022 FIFA World Cup?",
    "correct_answer": "Qatar",
    "incorrect_answers": [
      "USA",
      "Japan",
      "Switzerland"
    ]
  }
]

For example I need to have "Qatar" included into the same array as the incorrect_answers... and this goes for each object in the array.

"correct_answer": "Qatar",
    "incorrect_answers": [
      "USA",
      "Japan",
      "Switzerland"

​

​

Posted Jan 4, 2023, 6:07 PM UTC · edited

210
Loading comments…