GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing www.geeksforgeeks.org — Reverse a String in JavaScript - GeeksforGeeks Reverse a String in JavaScriptLast Updated : 20 Dec, 2025 We have given an input string, and the task is to reverse the input string in JavaScript. ![]() Below are the following approaches by which we can reverse a string in JavaScript: 1. Using split(), reverse() and join()In this approach, we’ll use three built-in methods:
Output olleh 2. Using a for loopWe use a for loop to iterate through the string from the last character to the first. At each step, we build a new string by adding the current character to the result.
Output skeeGrofskeeG 3. Using RecursionFor this solution, we will use two methods: the String.prototype.substr() method and the String.prototype.charAt() method. The substr() method returns the portion of a string starting at the specified position and continuing for a given number of characters. Example: "hello".substr(1); // "ello"The Example: "hello".charAt(0); // "h"
Output skeeGrofskeeG 4. Using Spread OperatorThe 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.
Output skeeGrofskeeG Comment Explore |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |