> For the complete documentation index, see [llms.txt](https://jscula.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jscula.gitbook.io/docs/array/shuffle.md).

# shuffle

Shuffles an array in place and returns it.

```javascript
const cards = ['a', 'b', 'c', 'd'];

cards.shuffle(); //['b','d','a','c']
```

### Use cases

Use `shuffle()` to randomize an existing order:

* Randomize quiz questions.
* Vary the order of product suggestions.
* Deal cards for a game interface.

### More examples

Randomize questions before rendering a quiz:

```javascript
const questions = ['HTML', 'CSS', 'JavaScript'];

questions.shuffle();
renderQuiz(questions);
```

Shuffle suggestion cards:

```javascript
const suggestions = ['Starter', 'Pro', 'Team'];

suggestions.shuffle();
```

{% hint style="info" %}
`shuffle()` changes the original array. The resulting order differs each time.
{% endhint %}
