Have you noticed why "card2" is randomly adding an object to the array? It should consistently add objects to the array.
const cards=[
{
card: '🂡',
value: '1'
},
{
card: '🂢',
value: '2'
},
{
card: '🂣',
value: '3'
},
{
card: '🂤',
value: '4'
},
{
card: '🂥',
value: '5'
},
{
card: '🂦',
value: '6'
},
{
card: '🂧',
value: '7'
},
{
card: '🂨',
value: '8'
},
{
card: '🂩',
value: '9'
},
{
card: '🂪',
value: '10'
}
];
var deck = [];
shuffleDeck = () =>{
var tempDeck = [...cards];
var card1 = [0];
var card2 = [0];
while(0 !== tempDeck.length) {
var randomIndex = Math.floor(Math.random() * tempDeck.length);
card1 = tempDeck.splice(randomIndex, 1);
card2 = tempDeck.splice(randomIndex, 1);
deck = [...card1, ...card2];
}
}
shuffleDeck();
for(var i = 0; i <= deck.length; i++){
console.log(deck[i]);
}