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 — JavaScript Reverse a string in place - GeeksforGeeks JavaScript Reverse a string in placeLast Updated : 11 Jul, 2025 JavaScript reverses a string in place refers to the process of flipping the order of characters within the string without using additional memory. It involves iterating through the string and swapping characters from both ends until reaching the middle. Reverse a string in place ExampleUsing the JavaScript split() methodJavaScript String split() Method is used to split the given string into an array of strings by separating it into substrings using a specified separator provided in the argument. Example: This example reverses the string by first splitting it with ("") separator and then reversing it and finally joining it with ("") separator.
Output Input string is : This is GeeksForGeeks Reverse StringskeeGroFskeeG si sihT Using the Array reverse() methodJavaScript Array.reverse() Method is used for the in-place reversal of the array. The first element of the array becomes the last element and vice versa. Example: This example uses the concept of the merge sort algorithm.
Output Input string is : This is GeeksForGeeks skeeGroFskeeG si sihT Using the Array join() methodThe JavaScript Array join() Method is used to join the elements of an array into a string. The elements of the string will be separated by a specified separator and its default value is a comma(, ). Example: This example takes a variable and appends the result from the end of the string.
Output Input string is : A Computer Science Portal latroP ecneicS retupmoC A Using substr() methodJavaScript str.substr() method returns the specified number of characters from the specified index from the given string. It basically extracts a part of the original string. Example: This example uses str.substr() method to reverse a string.
Output Input string is : This is GeeksForGeeks skeeGroFskeeG si sihT Using for loopTo reverse a string in place using a for loop in JavaScript, iterate over half the string length, swapping characters from both ends until reaching the middle. Return the modified string. Example: In this example the function iterates backward through the string, appending each character to a new string, effectively reversing it. Then, it returns the reversed string.
Output Original string is: This is GeekForGeeks Reversed string is: skeeGroFkeeG si sihT Using the Array reduce() methodJavaScript Array reduce() method executes a reducer function on each element of the array, resulting in a single output value. It can be utilized to reverse a string by iterating over each character and prepending it to an accumulator string. Example:
Output Input string is : This is GeeksForGeeks skeeGroFskeeG si sihT Using Two-Pointer TechniqueThe two-pointer technique involves using two pointers, one starting from the beginning of the string and the other from the end. By swapping the characters at these pointers and moving the pointers towards each other until they meet in the middle, we can reverse the string in place. Example:This example demonstrates how to reverse a string using the two-pointer technique.
Output Original string is: This is GeeksForGeeks Reversed string is: skeeGroFskeeG si sihT 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. |