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
1019

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.

🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › reverse
Array.prototype.reverse() - JavaScript | MDN
The reverse() method is generic. It only expects the this value to have a length property and integer-keyed properties. Although strings are also array-like, this method is not suitable to be applied on them, as strings are immutable.
🌐
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
🌐
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 - Interviewers may ask you to write different ways to reverse a string, or they may ask you to reverse a string without using in-built methods, or they may even ask you to reverse a string using recursion. There are potentially tens of different ways to do it, excluding the built-in reverse function, as JavaScript does not have one.
🌐
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 - The final method uses the same half-indexing idea as the previous implementation but relies on recursion to reverse the string instead of a for-loop. It is all fun and games being a JavaScript ninja and finding interesting tricks to complete quite a mundane task.
Find elsewhere
🌐
CoreUI
coreui.io › answers › how-to-reverse-a-string-in-javascript
How to reverse a string in JavaScript · CoreUI
May 18, 2026 - Use split(), reverse(), and join() methods to reverse the character order of a string.
🌐
W3Schools
w3schools.com › jsref › jsref_reverse.asp
JavaScript Array reverse() Method
The reverse() method overwrites the original array. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: sales@w3schools.com · If you want to report an error, or if you want to make ...
🌐
Medium
medium.com › codex › reverse-string-on-javascript-d6a4e0ce8c68
Reverse String on JavaScript. Did you ever try to read an open book… | by Norberto Santiago | CodeX | Medium
December 24, 2021 - As long as i is longer or equals 0, i will decrement. For each iteration, the last character will be added to newString, forming the result reversed string we want. ... We get a pool. ... Now that we tried reversing with the good old for loop, let’s go ahead and do some JavaScript tricks.
🌐
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
Afterward, it forms a single string with these reversed words, producing "olleH taen 321_srevol_tpircsavaj". Therefore, if you call reverseWords("Hello neat javascript_lovers_123"), the function should return "olleH taen 321_srevol_tpircsavaj".
🌐
Medium
medium.com › @matt.readout › string-reversal-with-javascript-bd96983ab2a7
String Reversal with JavaScript. A brief look at a couple solutions to a… | by matt readout | Medium
August 4, 2019 - Sure enough, calling the reverse() method on an array reverses it in place. Using this as our starting point, we can now make use of a string helper method to take our string input, convert it to an array of characters, on which we can call reverse() to reverse the order of the array, and then convert the reversed array back into a string that our function can return.
🌐
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
🌐
DEV Community
dev.to › swarnaliroy94 › reverse-a-string-in-javascript-e1i
Reverse a String in JavaScript - DEV Community
September 10, 2021 - The function stringReversed returns the current value adding it with the previous value, which is actually reversing the whole array characters and joining them together in a reversed way.
🌐
Google
developers.google.com › google maps platform › web › maps javascript api › place id finder
Place ID Finder | Maps JavaScript API | Google for Developers
<html> <head> <title>Place ID Finder</title> <link rel="stylesheet" type="text/css" href="./style.css" /> <script type="module" src="./index.js"></script> <script> // prettier-ignore (g=>{var h,a,k,p="The Google Maps JavaScript API",c="google",l="importLibrary",q="__ib__",m=document,b=window;b=b[c]||(b[c]={});var d=b.maps||(b.maps={}),r=new Set,e=new URLSearchParams,u=()=>h||(h=new Promise(async(f,n)=>{await (a=m.createElement("script"));e.set("libraries",[...r]+"");for(k in g)e.set(k.replace(/[A-Z]/g,t=>"_"+t[0].toLowerCase()),g[k]);e.set("callback",c+".maps."+q);a.src=`https://maps.${c}apis.com/maps/api/js?`+e;d[q]=f;a.onerror=()=>h=n(Error(p+" could not load."));a.nonce=m.querySelector("script[nonce]")?.nonce||"";m.head.append(a)}));d[l]?console.warn(p+" only loads once.
🌐
Fueler
fueler.io › blog › reverse-string-in-javascript-tutorial
Reverse String in JavaScript: A Simple Tutorial
August 6, 2023 - Learn how to easily reverse a string in JavaScript in just a few lines of code using String methods. Everything you need to know about reversing strings in JS in this simple tutorial.
🌐
Futurestud.io
futurestud.io › tutorials › reverse-a-string-in-javascript-or-node-js
Reverse a String in JavaScript or Node.js
December 9, 2021 - Then you must join the items in the array back to a string value: /** * Returns the reverse of the given string `value`. * * @param {String} value * * @returns {String} */ function reverse(value) { return Array.from( String(value || '') ).reverse().join('') }
🌐
DEV Community
dev.to › sarah_chima › reverse-a-string-four-javascript-solutions-2nbm
Reverse a String - Four JavaScript Solutions - DEV Community
July 17, 2019 - Reversing a string is, well, reversing a string. Okay, here's the problem statement: Write a function that reverses a string. If you pass "Sarah" to the function, it should return "haraS" and "listen" should become "netsil".
🌐
Code Beautify
codebeautify.org
Code Beautify and Code Formatter For Developers - to Beautify, Validate, Minify, JSON, XML, JavaScript, CSS, HTML, Excel and more
Free Online Tools like Code Beautifiers, Code Formatters, Editors, Viewers, Minifier, Validators, Converters for Developers: XML, JSON, CSS, JavaScript, Java, C#, MXML, SQL, CSV, Excel