As long as you're dealing with simple ASCII characters, and you're happy to use built-in functions, this will work:

function reverse(s){
    return s.split("").reverse().join("");
}

If you need a solution that supports UTF-16 or other multi-byte characters, be aware that this function will give invalid unicode strings, or valid strings that look funny. You might want to consider this answer instead.

The array expansion operator is Unicode aware:

function reverse(s){
    return [...s].reverse().join("");
}

Another Unicode aware solution using split(), as explained on MDN, is to use a regexp with the u (Unicode) flag set as a separator.

function reverse(s){
    return s.split(/(?:)/u).reverse().join("");
}
Answer from belacqua on Stack Overflow
Top answer
1 of 16
1016

As long as you're dealing with simple ASCII characters, and you're happy to use built-in functions, this will work:

function reverse(s){
    return s.split("").reverse().join("");
}

If you need a solution that supports UTF-16 or other multi-byte characters, be aware that this function will give invalid unicode strings, or valid strings that look funny. You might want to consider this answer instead.

The array expansion operator is Unicode aware:

function reverse(s){
    return [...s].reverse().join("");
}

Another Unicode aware solution using split(), as explained on MDN, is to use a regexp with the u (Unicode) flag set as a separator.

function reverse(s){
    return s.split(/(?:)/u).reverse().join("");
}
2 of 16
440

The following technique (or similar) is commonly used to reverse a string in JavaScript:

// Don’t use this!
var naiveReverse = function(string) {
    return string.split('').reverse().join('');
}

In fact, all the answers posted so far are a variation of this pattern. However, there are some problems with this solution. For example:

naiveReverse('foo 𝌆 bar');
// → 'rab �� oof'
// Where did the `𝌆` symbol go? Whoops!

If you’re wondering why this happens, read up on JavaScript’s internal character encoding. (TL;DR: 𝌆 is an astral symbol, and JavaScript exposes it as two separate code units.)

But there’s more:

// To see which symbols are being used here, check:
// http://mothereff.in/js-escapes#1ma%C3%B1ana%20man%CC%83ana
naiveReverse('mañana mañana');
// → 'anãnam anañam'
// Wait, so now the tilde is applied to the `a` instead of the `n`? WAT.

A good string to test string reverse implementations is the following:

'foo 𝌆 bar mañana mañana'

Why? Because it contains an astral symbol (𝌆) (which are represented by surrogate pairs in JavaScript) and a combining mark (the in the last mañana actually consists of two symbols: U+006E LATIN SMALL LETTER N and U+0303 COMBINING TILDE).

The order in which surrogate pairs appear cannot be reversed, else the astral symbol won’t show up anymore in the ‘reversed’ string. That’s why you saw those �� marks in the output for the previous example.

Combining marks always get applied to the previous symbol, so you have to treat both the main symbol (U+006E LATIN SMALL LETTER N) as the combining mark (U+0303 COMBINING TILDE) as a whole. Reversing their order will cause the combining mark to be paired with another symbol in the string. That’s why the example output had instead of ñ.

Hopefully, this explains why all the answers posted so far are wrong.


To answer your initial question — how to [properly] reverse a string in JavaScript —, I’ve written a small JavaScript library that is capable of Unicode-aware string reversal. It doesn’t have any of the issues I just mentioned. The library is called Esrever; its code is on GitHub, and it works in pretty much any JavaScript environment. It comes with a shell utility/binary, so you can easily reverse strings from your terminal if you want.

var input = 'foo 𝌆 bar mañana mañana';
esrever.reverse(input);
// → 'anañam anañam rab 𝌆 oof'

As for the “in-place” part, see the other answers.

🌐
GeeksforGeeks
geeksforgeeks.org › javascript › reverse-a-string-in-javascript
Reverse a String in JavaScript - GeeksforGeeks
The spread operator(...) is used to spread the characters of the string str into individual elements. The reverse() method is then applied to reverse the order of the elements, and join() is used to combine the reversed elements back into a string.
Published   December 20, 2025
Discussions

Reversing a string - Blog Post
What’s the use-case? More on reddit.com
🌐 r/learnjavascript
14
3
July 22, 2023
How would you reverse a string in JavaScript without using split(), reverse(), or join()?
I have never been asked that question in my life and if I was, my first response would be “why”. More on reddit.com
🌐 r/learnjavascript
38
0
April 25, 2025
Reverse String in JavaScript - Stack Overflow
I wrote a JS constructor which reverse a string variable: More on stackoverflow.com
🌐 stackoverflow.com
How to reverse string using Javascript | OutSystems
How to reverse string using Javascript also how to assign it in output · Everyone here is giving the exact same answer. Turns string into array and reverse the array More on outsystems.com
🌐 outsystems.com
March 6, 2025
🌐
freeCodeCamp
freecodecamp.org › news › how-to-reverse-a-string-in-javascript-in-3-different-ways-75e4763c68cb
Three Ways to Reverse a String in JavaScript
March 14, 2016 - The split() method splits a String object into an array of string by separating the string into sub strings. The reverse() method reverses an array in place.
🌐
CoreUI
coreui.io › answers › how-to-reverse-a-string-in-javascript
How to reverse a string in JavaScript · CoreUI
September 22, 2025 - From my extensive expertise, the most straightforward and readable solution is using the combination of split(), reverse(), and join() methods to convert the string to an array, reverse it, and convert back.
Find elsewhere
🌐
Scaler
scaler.com › topics › reverse-string-in-javascript
How to Reverse a String in JavaScript? - Scaler Topics
September 12, 2022 - The simplest way to reverse a string in JavaScript is to split a string into an array, reverse() it and join() it back into a string. Let's deep-dive into the methods on Scaler Topics.
🌐
Edd Mann
eddmann.com › posts › ten-ways-to-reverse-a-string-in-javascript
Ten ways to reverse a string in JavaScript - Edd Mann
October 31, 2011 - JSPref allows you to create unit-style test suites, which can then be run on any browser you have access to. What makes this tool so great is that it stores the results of each run in the cloud, providing easily accessible, meaningful graphs and statistics. In the test suite, each function was called multiple times (with time measured and an average calculated) one after the other with a randomly generated 20-character-long string to be reversed.
🌐
Reddit
reddit.com › r/learnjavascript › how would you reverse a string in javascript without using split(), reverse(), or join()?
r/learnjavascript on Reddit: How would you reverse a string in JavaScript without using split(), reverse(), or join()?
April 25, 2025 -

Interviewers love to ask: "Reverse a string without using JavaScript's built-in methods." 🔥

I tried solving it manually by:

  • Starting from the last character

  • Appending each character to a new string

I explained my approach with code here if anyone wants to check it out: https://www.youtube.com/watch?v=N_UVJlnmD7w

Curious — how would you solve it differently? Would love to learn new tricks! 🚀

🌐
Quora
quora.com › How-do-you-reverse-a-string-in-JavaScript
How to reverse a string in JavaScript - Quora
Answer (1 of 6): If you want to reverse the string Manually then try this [code]var str = 'JSON'; var reverseStr = ''; for(var i = str.length-1; i>= 0; i--) { reverseStr += str[i]; } console.log(reverseStr); [/code]You can also assign the str[i] to str+= str[i] like this but this will change you...
🌐
YouTube
youtube.com › watch
How to Reverse a String in JavaScript | Easy Step-by-Step Tutorial - YouTube
🔄 Learn How to Reverse a String in JavaScript | Simple Methods Explained (2025 Tutorial)Want to reverse a string in JavaScript? Whether for coding challenge...
Published   June 11, 2025
🌐
CodeSignal
codesignal.com › learn › courses › practicing-string-operations-and-type-conversions-in-javascript › lessons › reversing-words-in-a-string-in-javascript
Reversing Words in a String in JavaScript
Reversed using the reverse() method. Joined back into a string using the join('') method, which concatenates the reversed characters without any separators.
🌐
W3Resource
w3resource.com › javascript-exercises › javascript-basic-exercise-48.php
JavaScript basic: Reverse a given string - w3resource
// Define a function named string_reverse with a parameter str function string_reverse(str) { // Split the string into an array of characters, reverse the order, and join them back into a string return str.split("").reverse().join(""); } // ...
🌐
ReqBin
reqbin.com › code › javascript › lqai57s8 › javascript-reverse-string-example
How do I reverse a string in JavaScript?
December 16, 2022 - To reverse a string in JavaScript, you can use a combination of three built-in methods: split(), reverse(), and join(). The first method splits a string into an array of characters and returns a new array.
🌐
Index.dev
index.dev › blog › reverse-string-javascript-methods
How to Reverse a String in JavaScript: 6 Proven Techniques
May 30, 2025 - Here's what's happening: first, we break our string into individual characters with split('') (creating an array of UTF-16 code units), flip the entire thing backwards using JavaScript's built-in reverse() method, and then glue everything back ...
Top answer
1 of 8
7

The length problem is already explained. To solve it you could use:

function ReverseString(string) {
    this.str = string;
    var size = this.str.length;
    this.reverse = function () {
        while(size--) {
            console.log(this.str[size]);
        }
    }
}

Another (more simple way) to reverse a string is to split it into an array, reverse that, and join again:

somestring.split('').reverse().join('');

Applied to your method, something like this snippet:

const result = document.querySelector('#result');
const RString = stringFactory();

// constructor
const myReversed = new ReverseString('hello world');
myReversed.reverse();

// factory
result.textContent += ` | `;
RString(`Hello World`).printReversed(result);

function ReverseString(string) {
  this.str = string;
  this.reverse = function() {
    const rev = this.str.split('').reverse();
    rev.forEach(v => result.textContent += v);
    this.reversed = rev.join('');
  };
}

// factory pattern
// see also https://github.com/KooiInc/es-stringbuilder-plus
function stringFactory() {
  return str => assignHelpers(str);
  
  function assignHelpers(str) {
    return {
      get reverse() { return str.split('').reverse().join(``); },
      printReversed(elem) {
        str.split('').reverse().forEach( l => 
          elem.textContent += l );
      }
    };
  }
}
#result {
  letter-spacing: 0.5rem;
  font-size: 1.3rem;
  font-weight: bold;
}
<div id="result"></div>

To circumvent the problem @Mark Baijens commented on (combined Unicode characters, aka surrogate pairs), a modern solution (es20xx) could be:

const str = `foo 𝌆 bar mañaña`;
document.querySelector(`#result`)
  .textContent = [...str].reverse().join(``);
#result {
  letter-spacing: 0.5rem;
  font-size: 1.3rem;
  font-weight: bold;
}
<div id="result"></div>

2 of 8
3

What about this easy step

"hello world".split(' ').map(word=>word.split('').reverse().join('')).join(' ')

it will reverse every word in its place

"olleh dlrow"
🌐
Inspector
inspector.dev › home › how to reverse a string in javascript – fast tips
How to reverse a string in Javascript - Fast tips
November 7, 2024 - Three basic ways to reverse a string in JavaScript: utilizing the built-in reverse() method, a for loop, and the spread operator + reverse().
🌐
Futurestud.io
futurestud.io › tutorials › reverse-a-string-in-javascript-or-node-js
Reverse a String in JavaScript or Node.js
JavaScript doesn’t have a native Str#reverse method. Yet, you can use the existing methods to build your own method to reverse a string.
🌐
OutSystems
outsystems.com › forums › discussion › 101870 › how-to-reverse-string-using-javascript
How to reverse string using Javascript | OutSystems
March 6, 2025 - How to reverse string using Javascript also how to assign it in output · Everyone here is giving the exact same answer. Turns string into array and reverse the array