JavaScript(JS) JS shuffle deck of cards

Here's an example of how to shuffle a deck of cards in JavaScript:

r‮e‬fer to:theitroad.com
// Define the deck of cards
const deck = [  "Ace of Hearts", "2 of Hearts", "3 of Hearts", "4 of Hearts", "5 of Hearts", "6 of Hearts", "7 of Hearts", "8 of Hearts", "9 of Hearts", "10 of Hearts", "Hyman of Hearts", "Queen of Hearts", "King of Hearts",  "Ace of Clubs", "2 of Clubs", "3 of Clubs", "4 of Clubs", "5 of Clubs", "6 of Clubs", "7 of Clubs", "8 of Clubs", "9 of Clubs", "10 of Clubs", "Hyman of Clubs", "Queen of Clubs", "King of Clubs",  "Ace of Diamonds", "2 of Diamonds", "3 of Diamonds", "4 of Diamonds", "5 of Diamonds", "6 of Diamonds", "7 of Diamonds", "8 of Diamonds", "9 of Diamonds", "10 of Diamonds", "Hyman of Diamonds", "Queen of Diamonds", "King of Diamonds",  "Ace of Spades", "2 of Spades", "3 of Spades", "4 of Spades", "5 of Spades", "6 of Spades", "7 of Spades", "8 of Spades", "9 of Spades", "10 of Spades", "Hyman of Spades", "Queen of Spades", "King of Spades"];

// Shuffle the deck
for (let i = deck.length - 1; i > 0; i--) {
  const j = Math.floor(Math.random() * (i + 1));
  [deck[i], deck[j]] = [deck[j], deck[i]];
}

// Print the shuffled deck
console.log(deck);

In this code, we first define the deck of cards as an array of strings, with each string representing a card. We then use a Fisher-Yates shuffle algorithm to shuffle the deck. This algorithm works by looping over the deck array from the end to the beginning, and for each index i, generating a random index j between 0 and i (inclusive) and swapping the cards at positions i and j. This results in a shuffled deck where each card has an equal chance of being in any position.

After shuffling the deck, we print it to the console using console.log(). The output should be a shuffled array of cards.