向Javascript添加输入类型的Javascript测试

向Javascript添加输入类型的Javascript测试,javascript,Javascript,我正在创建一个随机问题测验,我想添加不同类型的输入,但不知道如何添加。是的,我知道如何在HTML中添加,但我想将其添加到问题数组中 如何将单选按钮、文本输入或图像添加到以下代码中 const myQuestions = [ { question: "What is the name of the actor The Rock?", answers: [ { text: 'Dwayne Johnson', correct: tr

我正在创建一个随机问题测验,我想添加不同类型的输入,但不知道如何添加。是的,我知道如何在HTML中添加,但我想将其添加到问题数组中

如何将单选按钮、文本输入或图像添加到以下代码中

 const myQuestions = [
{
    question: "What is the name of the actor The Rock?",
        answers: [
            { text: 'Dwayne Johnson', correct: true },
            { text: 'Paul Walker', correct: false },
            { text: 'Vin Diesel', correct: false },
            { text: 'Tyrese Gibson', correct: false }

        ]
    }
])

在这里。这就是我如何使用数组

function showQuestion(question) {
questionsElements.innerText = question.question;
console.log(question.question);

question.answers.forEach(answer => {
    const button = document.createElement("radio");
    button.innerText = answer.text;
    
    button.classList.add('radio');  
    if (answer.correct) {
        button.dataset.correct = answer.correct;
    }

    button.addEventListener("click", selectAnswer);
    answerButtons.appendChild(button);
})

}

如何将属性添加到对象-
{question:'..,inputType:'..,answers:[..]}
@ShivamSingla你能给我一个快速的代码示例如何实现它吗?请粘贴代码,你是如何使用
myQuestions
数组的。现在我很困惑。你所说的“不同类型的输入”是什么意思?@ShivamSingla好的,所以我想问一个问题来显示图像并问“这是谁”,一个问题让用户用文字给出答案,最后一个选项是使用单选按钮