Here is the simplest way to do without using any javascript inbuilt function.

function reverse1(str){
  let r = "";
  for(let i = str.length-1; i >= 0; i--){
    r += str[i];
  }
  return r;
}

console.log(reverse1("javascript"))

Answer from vipul suryavanshi on Stack Overflow
๐ŸŒ
DEV Community
dev.to โ€บ imranshaik012 โ€บ reverse-a-string-in-javascrip-without-using-reverse-method-5cgo
Reverse a string in JavaScript without using reverse() - DEV Community
December 22, 2024 - The += operator simplifies the process of building the reversed string incrementally without needing an array or additional logic. It's efficient purpose in JavaScript ... Experienced Software Engineer with a demonstrated history of working ...
Discussions

javascript - How do you reverse a string in-place? - Stack Overflow
Find centralized, trusted content ... you use most. Learn more about Collectives ... Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... Save this question. Show activity on this post. How do you reverse a string in-place in JavaScript when it is passed to a function with a return statement, without using built-in ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Reverse string in JavaScript without using reverse() - Code Review Stack Exchange
I have to reverse a string in JavaScript and cannot use the built in reverse() function. More on codereview.stackexchange.com
๐ŸŒ codereview.stackexchange.com
April 5, 2017
javascript - How to reverse strings in js without using methods - Stack Overflow
Without using the split reverse and join functions, how would one do such a thing? The Problem Given: Reverse the words in a string Sample Input: "Hello World" Sample Output: "World Hello" More on stackoverflow.com
๐ŸŒ stackoverflow.com
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
๐ŸŒ
Java Guides
javaguides.net โ€บ 2023 โ€บ 09 โ€บ javascript-reverse-string-without-built-in-reverse-function.html
JavaScript: Reverse a String without Built-in reverse() Function
September 6, 2024 - A loop is used to swap the characters from the start and end of the array until the middle is reached. The array is then joined back into a string using join(''). Original String: hello Reversed String (For Loop): olleh Reversed String (Recursion): olleh Reversed String (Array Manipulation): olleh ยท This JavaScript program demonstrates three different methods to reverse a string without using the built-in reverse() function.
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 manฬƒana');
// โ†’ 'anaฬƒ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 manฬƒana'

Why? Because it contains an astral symbol (๐Œ†) (which are represented by surrogate pairs in JavaScript) and a combining mark (the nฬƒ in the last manฬƒ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 aฬƒ 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 manฬƒana';
esrever.reverse(input);
// โ†’ 'ananฬƒam anaรฑam rab ๐Œ† oof'

As for the โ€œin-placeโ€ part, see the other answers.

Top answer
1 of 3
9
  1. One array to rule them all

    You do not need to create two arrays; one is enough. Simply swap slots until you've reached the "middle" of the array.

  2. Declare your variables

    It is better to use the var keyword to define your variables. Otherwise, they are declared on the top-level scope, i.e; they become global, and may be accessed and modified by other functions.

  3. Why not use reverse()?

    You do not say why you cannot use built-in functions. If you happen to have some base code which overrides native functions, then some groaning and roaring is in order.

function reverse(str) {
  var chars = str.split("");
  var length = chars.length;
  var half = length / 2;
  for (var ii = 0; ii < half; ii++) {
    var temp = chars[ii];
    var mirror = length - ii - 1;
    chars[ii] = chars[mirror];
    chars[mirror] = temp;
  }
  return chars.join("");
}

console.log(reverse("abcd"));
console.log(reverse("abcde"));

2 of 3
7

I was wondering if there's a need to split at all, because characters are accessible directly using String#charAt.

This implementation (which is almost the same as yours - only with the split) should be among the fastest.

function reverse(str) {
  var result = [];
  for (var i = str.length - 1; i >= 0; i--) {
    result.push(str.charAt(i));
  }
  return result.join("");
}

console.log(reverse("abcde"));

According to some benchmark, String concatenation is better optimized than Array.join, it also makes the code cleaner:

function reverse(str) {
  var result = "";
  for (var i = str.length - 1; i >= 0; i--) {
    result += str.charAt(i);
  }
  return result;
}

console.log(reverse("abcde"));

As a side-note, you can get creative by using Array.prototype.reduce and allow JavaScript duck-type the String as an Array.

function reverse(str) {
  return Array.prototype.reduce.call(str, function(result, c) {
    return c + result;
  }, "");
}

console.log(reverse("Hello world!"));

And going further you can make an ES6 one-liner:

let reverse = str => Array.prototype.reduce.call(str, (result, c) => c + result, "");

console.log(reverse("Hello world!"));

JSFiddle forked from @Andreas: https://jsfiddle.net/kazenorin/6shbv6hs/2/

๐ŸŒ
Medium
medium.com โ€บ free-code-camp โ€บ how-to-reverse-a-string-in-javascript-in-3-different-ways-75e4763c68cb
Three Ways to Reverse a String in JavaScript | by Sonya Moisset | Weโ€™ve moved to freeCodeCamp.org/news | Medium
February 16, 2017 - Your result must be a string. ... solution, we will use three methods: the String.prototype.split() method, the Array.prototype.reverse() method and the Array.prototype.join() method....
๐ŸŒ
Medium
medium.com โ€บ cracking-the-coding-interview-in-ruby-python-and โ€บ three-ways-to-reverse-a-string-without-reverse-mastering-javascript-77f9d1672ef0
Three Ways To Reverse a String Without Reverse: Mastering Javascript | by Patrick Karsh | Cracking The Coding Interview in Ruby, Python And JavaScript | Medium
November 8, 2023 - The space complexity of this function is O(n) as well. Inside the loop, you are continuously appending characters to the reversed string, and the space required to store the reversed string grows with the size of the input string. Since you are creating a new string that is the same length as the input string, the space complexity is linear with respect to the length of the input string. Reversing a string in place without using the reverse() method in JavaScript ...
Find elsewhere
๐ŸŒ
Medium
medium.com โ€บ @stheodorejohn โ€บ reversing-a-string-without-using-built-in-methods-1e9ab32d502e
Reversing a String Without Using Built-in Methods | by Theodore John.S | Medium
June 18, 2023 - While most programming languages provide built-in functions or methods to reverse a string, itโ€™s also interesting to explore alternative approaches. In this article, we will discuss the problem statement, provide a JavaScript code snippet that implements a method to reverse a string without ...
๐ŸŒ
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 - Reversing a string is one of the most frequently asked JavaScript question in the technical round of interview. 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.
๐ŸŒ
Stack Overflow
stackoverflow.com โ€บ questions โ€บ 34004740 โ€บ how-to-reverse-strings-in-js-without-using-methods
javascript - How to reverse strings in js without using methods - Stack Overflow
var string = "Hello World", words = [], reversedString="", i; for (i=0; i<string.length; i++) { if (string.charAt(i) === " ") { words.push(string.substring(0, i)); words.push(string.substring(i)); } } for (i=words.length-1; i>=0; i--) { reversedString += words[i]; }
๐ŸŒ
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-can-I-reverse-words-in-a-string-without-using-a-built-in-function-in-JavaScript
How to reverse words in a string without using a built-in function in JavaScript - Quora
Answer (1 of 7): String manipulation is one of those cheesy programming interview questions meant to determine if you understand sequence traversal or just know how to search for copy-paste targets with Google or Stack Overflow (or Quora!) Writing an algorithm to solve any general problem books ...
๐ŸŒ
YouTube
youtube.com โ€บ watch
How to Reverse a String in JavaScript Without Using the Reverse Array Method - YouTube
If you want to become a developer, then you need to be able to come up with solutions to problems. In this series I teach the algorithms that you'll be expec...
Published ย  January 3, 2021
๐ŸŒ
WsCube Tech
wscubetech.com โ€บ blog โ€บ reverse-string-javascript
Reverse a String in JavaScript (7 Programs)
January 20, 2026 - Learn 7 ways to reverse strings in JavaScript using efficient methods. Improve your coding skills with easy-to-understand programs and examples.
๐ŸŒ
freeCodeCamp
forum.freecodecamp.org โ€บ javascript
Other ways to reverse a string - JavaScript - The freeCodeCamp Forum
May 8, 2022 - Tell us whatโ€™s happening: The very bottom is my code that reverses a string. I was curious what other ways there were to achieve the same goal. Here are a few questions I had about ways to do things. Is it possible toโ€ฆ
๐ŸŒ
Board Infinity
boardinfinity.com โ€บ blog โ€บ reverse-a-string-in-javascript
String Reverse in Javascript | Board Infinity
July 9, 2023 - One of the most typical JavaScript interview questions during the technical round is how to reverse a string. Interviewers could ask you to build various techniques for reversing strings, to do it without the use of built-in methods, or even to do so by utilising recursion. Several tens of methods might be used, eliminating the built-in reverse function as JavaScript lacks one.
๐ŸŒ
DEV Community
dev.to โ€บ onlinemsr โ€บ javascript-reverse-string-3-best-ways-to-do-it-8co
JavaScript Reverse String: 3 Best Ways To Do It - DEV Community
July 3, 2023 - To reverse a string using the reverse() method is simple and straightforward. If you want to reverse a string without using the built-in reverse() method, you can use for loop or reduce() methods.