dimanche 1 août 2021

How to randomize/shuffle a JavaScript array that has id without any repetition? [duplicate]

I have an array like this:

export const QuizArray = [
    {
        id: 1, 
        question: 'Which of these factors that contribute to stroke?',
        answers: ['High blood cholesterol', 'Smoking', 'Old Age', 'All of the above'],
        correct_answer: 'All of the above',
    },
    {
        id: 2, 
        question: 'Ischaemic Stroke is when blood clots occur in the brain?',
        answers: ['TRUE', 'FALSE'],
        correct_answer: 'TRUE',
    },

    {
        id: 3, 
        question: 'Which of the following are possible symptoms of stroke?',
        answers: ['Weakness in facial muscles', 'Vision impairment', 'Slurring of speech', 'All of the above'],
        correct_answer: 'All of the above',
    },
    
]

How do I randomise/shuffle the id without any repetition? I am using react native, VS Code and Andriod studio.




Aucun commentaire:

Enregistrer un commentaire