> For the complete documentation index, see [llms.txt](https://lochiwei.gitbook.io/web/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://lochiwei.gitbook.io/web/js/val/prim/str/method/string.shuffle.md).

# str.shuffle()

[🔰 JS](/web/js.md) ⟩ [Types](/web/js/val/type.md) ⟩ [String](/web/js/val/prim/str.md) ⟩ [methods](/web/js/val/prim/str/method.md)

{% tabs %}
{% tab title="string.shuffle()" %}

```javascript
/**
 * ⭐️ shuffleString()
 *    shuffle string
 * @param str [string] string to shuffle
 */
export function shuffleString(str){
    return shuffle(str.split('')).join('');
}

// ⭐️ string.shuffle()
String.prototype.shuffle = function(){
    return shuffleString(this);
}
```

{% endtab %}

{% tab title="⬆️ 需要" %}

* [randomInt()](/web/js/val/prim/num/random/randomint.md)
* [array.shuffle()](/web/js/val/builtin/arr/ext/arr.shuffle.md)
  {% endtab %}

{% tab title="📗 參考" %}

* [x] DEV ⟩ [How to shuffle an array in JavaScript](https://dev.to/codebubb/how-to-shuffle-an-array-in-javascript-2ikj)
  {% endtab %}
  {% endtabs %}
