Iterate Over PHP-Generated JSON Data for JavaScript Processing

I have PHP code that successfully produces JSON data, but I need this output to have a structure similar to the objects shown in the JavaScript sample below. How can I loop through the JSON data and use it in JavaScript in a comparable way?

<?php
$recordSet = array();
$sqlQuery = "SELECT question_id, question_text, opt_first, opt_second, opt_third, answer_key FROM quiz_items WHERE category = 'Mathematics'";
$result = $dbConnection->query($sqlQuery);
$result->setFetchMode(PDO::FETCH_ASSOC);

while ($item = $result->fetch()) {
    $recordSet['questions'][] = $item;
}
?>
const quizData = [
  { prompt: "What is 5+3?", options: [6, 8, 10, 7], correctIndex: 1 },
  { prompt: "What is 7-2?", options: [3, 4, 5, 6], correctIndex: 2 }
];

hey, try JSON.parse first so its an object then use a forEach loop to build your quiz questions. i had similar probs and once i did this it worked fine. hope this hepz