Logical Interview Questions and Answers in JavaScript : Reverse a string
2 min readMay 6, 2019
Reverse a string :
In JavaScript, you can reverse a string by three ways:
- Using default methods ( split (), reverse (), join ())
- Using decremented loop.
- Using of recursion function.
Using default methods:
Reverse a string by using three default or built-in functions:
- split () // split a string into array of character.
- reverse() // reverse the array.
- join() // join the element of the array.
Chaining all three default methods:
By using of decremented loop:
In the above function, we use the for loop for accessing the each alphabet from the last to first.
By the use of recursive method:
For reverse a string by recursive method, we can use two methods of string :
- substr(): The substr() method extracts parts of a string, beginning at the character at the specified position, and returns the specified number of characters.
2. charAt(): The charAt() method returns the character at the specified index in a string.
Hope you found this helpful. If you face any problem please leave a message to my email id: vsvaibhav2016@gmail.com