Javascript has a reverse() method that you can call in an array

var a = [3,5,7,8];
a.reverse(); // 8 7 5 3

Not sure if that's what you mean by 'libraries you can't use', I'm guessing something to do with practice. If that's the case, you can implement your own version of .reverse()

function reverseArr(input) {
    var ret = new Array;
    for(var i = input.length-1; i >= 0; i--) {
        ret.push(input[i]);
    }
    return ret;
}

var a = [3,5,7,8]
var b = reverseArr(a);

Do note that the built-in .reverse() method operates on the original array, thus you don't need to reassign a.

Answer from Andreas Wong on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › reverse
Array.prototype.reverse() - JavaScript - MDN Web Docs
The reverse() method of Array instances reverses an array in place and returns the reference to the same array, the first array element now becoming the last, and the last array element becoming the first. In other words, elements order in the array will be turned towards the direction opposite ...
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › reverse-an-array-in-javascript
Reverse an Array in JavaScript - GeeksforGeeks
JavaScript · const a = [1, 2, ... console.log(reversed); The recursive function removes the last element of the array using pop() and appends it to a new array....
Published   July 23, 2025
🌐
freeCodeCamp
freecodecamp.org › news › how-to-reverse-an-array-in-javascript-js-reverse-function
How to Reverse an Array in JavaScript – JS .reverse() Function
November 29, 2022 - You can use the reverse method, which is an easier-to-read/write approach to the for loop, to reverse an array. This method reverses the array in place, which means that the array it is used on is modified.
🌐
Medium
josephcardillo.medium.com › how-to-reverse-arrays-in-javascript-without-using-reverse-ae995904efbe
How to Reverse Arrays in JavaScript Without Using .reverse() | by Joe Cardillo | Medium
January 31, 2022 - Specifically, take this problem ... and reverseArrayInPlace. The first, reverseArray, takes an array as an argument and produces a new array that has the same elements in the inverse order....
🌐
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 - function reverseString(str) { return (str === '') ? '' : reverseString(str.substr(1)) + str.charAt(0); } reverseString("hello"); Reversing a String in JavaScript is a small and simple algorithm that can be asked on a technical phone screening or a technical interview.
🌐
W3Schools
w3schools.com › JsrEF › jsref_reverse.asp
JavaScript Array reverse() Method
The reverse() method reverses the order of the elements in an array.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › reverse-a-string-in-javascript
Reverse a String in JavaScript - GeeksforGeeks
The charAt() method returns the character at the specified index in a string. ... Note: This approach is not optimal for very long strings, as deep recursion can cause performance issues and stack overflow concerns. ... function reverseString(str) { if (str === "") { return str; } else { return reverseString(str.substr(1)) + str[0]; } } console.log(reverseString("GeeksforGeeks"));
Published   December 20, 2025
Find elsewhere
🌐
Inspector
inspector.dev › home › how to reverse a string in javascript – fast tips
How to reverse a string in Javascript - Fast tips - Inspector.dev
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().
🌐
Flexiple
flexiple.com › javascript › how-to-reverse-an-array
How to Reverse an Array In JavaScript – JS .reverse() Function - Flexiple
This function modifies the original array by reversing the order of its elements. Developers use this method to handle arrays where the sequence of elements needs to be inverted. Remember, JavaScript modifies the array in place, which means ...
🌐
SamanthaMing
samanthaming.com › pictorials › how-to-reverse-a-string
How to Reverse a String in JavaScript | SamanthaMing.com
function reverseString(str) { let result = ''; for (let i = str.length - 1; i >= 0; i--) { result += str[i]; } return result; } ... function reverseString(str = '') { const [head = '', ...tail] = str; if (tail.length) { return reverseString(tail) ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › TypedArray › reverse
TypedArray.prototype.reverse() - JavaScript - MDN Web Docs
July 10, 2025 - The reverse() method of TypedArray instances reverses a typed array in place and returns the reference to the same typed array, the first typed array element now becoming the last, and the last typed array element becoming the first. In other words, elements order in the typed array will be ...
🌐
GeeksforGeeks
geeksforgeeks.org › javascript-array-reverse-method
JavaScript Array reverse() Method | GeeksforGeeks
July 14, 2024 - It logs the original array, then reverses its order using the reverse() method, storing the result in new_arr, and logs the reversed array. ... function func() { // Original Array let arr = ['Portal', 'Science', 'Computer', 'GeeksforGeeks']; ...
🌐
TutorialsPoint
tutorialspoint.com › javascript › array_reverse.htm
JavaScript - Array reverse() Method
In JavaScript, the Array.reverse() method is used to reverse the order of the elements present in an array. In other words, the first element will become the last, and the last element will become the first element.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › toReversed
Array.prototype.toReversed() - JavaScript - MDN Web Docs
July 10, 2025 - The toReversed() method transposes the elements of the calling array object in reverse order and returns a new array.
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.

🌐
Programiz
programiz.com › javascript › examples › reverse-string
JavaScript Program to Reverse a String
To understand this example, you should have the knowledge of the following JavaScript programming topics: ... // program to reverse a string function reverseString(str) { // empty string let newString = ""; for (let i = str.length - 1; i >= 0; i--) { newString += str[i]; } return newString; } // take input from the user const string = prompt('Enter a string: '); const result = reverseString(string); console.log(result);
🌐
Board Infinity
boardinfinity.com › blog › reverse-a-string-in-javascript
String Reverse in Javascript | Board Infinity
July 9, 2023 - The reverse() function flips an array such that the first element is now the last and returns a reference to the same array.
🌐
Medium
medium.com › sonyamoisset › reverse-a-string-in-javascript-a18027b8e91c
Reverse a String in JavaScript. This article is based on Free Code Camp… | by Sonya Moisset | iDevOI | Medium
November 25, 2016 - For this solution, you will use three methods: the String.prototype.split() method, the Array.prototype.reverse() method and the Array.prototype.join() method. The split() method splits a String object into an array of string by separating the ...