{
category: 'Music',
id: '625064c2e12f6dec240bdfcb',
correctAnswer: "Don't Leave Me This Way",
incorrectAnswers: [
'Ice Ice Baby',
'In-A-Gadda-Da-Vida',
'Rebirth of Slick (Cool Like Dat)'
],
question: 'What song did Thelma Houston have a hit with in 1976?',
tags: [ 'songs', 'one_hit_wonders', 'music' ],
type: 'Multiple Choice',
difficulty: 'hard',
regions: []
}
// Here is the response from the API...
const oldArray = quizData[number].incorrectAnswers;
oldArray.push(quizData[number].correctAnswer);
console.log(oldArray);
// Here i am pushing the correctAnswer into the incorrect Answer array but my console.log keeps repeating the correct answer data, Why is this happening? Am i pushing it wrong?
['An arrow', 'A lightning bolt', 'A bottle of wine', 'A Discus', 'A Discus', 'A Discus', 'A Discus', 'A Discus']
//Here is my console.log array.
// 'A Discus' keeps getting repeated 4 times, Same length of the present array, So the array has 7 values instead of just 3, What is going on?
1条答案
按热度按时间hc2pp10m1#
使用扩展运算符以避免重复