Skip to content

shuffle

Shuffle an array.

WARNING

This function mutates the input array.

js
const arr = ['a', 'b', 'c']
shuffle(arr)
console.log(arr) // -> arr will be changed!

Demo

vue
<script setup lang="ts">
import { shuffle } from '.'

const arr = ref(['🍅', '🥑', '🍇', '🌽', '🍑'])
</script>

<template>
  <div>
    <button btn @click="shuffle(arr)">
      Shuffle!
    </button>

    <div flex="~ gap-4">
      <p v-for="key in arr" :key>
        {{ key }}
      </p>
    </div>
  </div>
</template>

🍅

🥑

🍇

🌽

🍑

Type Declarations

Details
ts
/**
 * Shuffle an array. This function mutates the array.
 *
 * @see {@link https://s3xysteak.github.io/fnclip/functions/array/shuffle/}
 */
export declare function shuffle<T>(array: T[], rand?: () => number): T[];

Source

SourceDemo