const questions = [ { questionText: <img src={`img//${question[0].image}`} />, answerOptions: [ { answerText: <img src={`img/${answer[Math.floor(Math.random() * 11)].image}`} />, isCorrect: false }, { answerText: <img src={`img/${answer[Math.floor(Math.random() * 11)].image}`} />, isCorrect: false }, { answerText: <img src={`img/${answer[0].image}`} />, isCorrect: true }, { answerText: <img src={`img/${answer[Math.floor(Math.random() * 11)].image}`} />, isCorrect: false }, ] } ]Por ejemplo, en la matriz de prueba, en lugar de Math.floor (Math.random() * 11) que genera un número del 0 al 11, debe excluir el índice 0 para que la lista de respuestas no sea la misma. También cómo tener las otras respuestas con un número de índice diferente.
Use splice para eliminar la respuesta correcta de la matriz, luego mezcle, luego use splice nuevamente para insertar el elemento nuevamente:
function shuffleArray(array) { for (let i = array.length - 1; i > 0; i--) { const j = Math.floor(Math.random() * (i + 1)); [array[i], array[j]] = [array[j], array[i]]; } } const answerOptions = [ { answerText: 'A', isCorrect: false }, { answerText: 'B', isCorrect: false }, { answerText: 'C', isCorrect: true }, { answerText: 'D', isCorrect: false }, ] const correctAnswerIndex = answerOptions.findIndex(answer => answer.isCorrect); const removed = answerOptions.splice(correctAnswerIndex, 1); shuffleArray(answerOptions); answerOptions.splice(correctAnswerIndex, 0, ...removed); console.log(answerOptions);