如何随机化/洗牌具有 id 的 JavaScript 数组而不重复?

时间:2021-08-01 15:03:30

标签: javascript arrays random shuffle

我有一个这样的数组:

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',
    },
    
]

如何在不重复的情况下随机化/洗牌 id?我正在使用 React Native、VS Code 和 Andriod studio。

0 个答案:

没有答案