> 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/str.reverse.md).

# str.reverse()

{% tabs %}
{% tab title="💾 程式" %}

```javascript
// reverseString()
export function reverseString(str) {
    return str.split("").reverse().join("");
}

// str.reverse()
String.prototype.reverse = function(){
    return reverseString(this);
}
```

{% endtab %}

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

* [x] freeCodeCamp ⟩ [Three Ways to Reverse a String in JavaScript](https://www.freecodecamp.org/news/how-to-reverse-a-string-in-javascript-in-3-different-ways-75e4763c68cb/)\
  1\. array.reverse()    2. for-loop   3. recursion
  {% endtab %}

{% tab title="📘 手冊" %}

* [array.reverse()](https://developer.mozilla.org/zh-TW/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse) - reverse **in place**. ⭐️
  {% endtab %}

{% tab title="👥 相關" %}

* [arr.reversed()](/web/js/val/builtin/arr/ext/arr.reversed.md)
  {% endtab %}
  {% endtabs %}
