Today we are going to discuss the String reverse process in JavaScript.It is one of the common questions in the interview board. Here I will show three ways to reverse a string in JavaScript.
Method 1 (Using String Method):
The string methods are given below:
.split()=> Is used to split a string into an array of substrings and returns the new array.
.reverse()=>Reverse the order reverses the order of the elements in an array
.join()=>return the array as a string
code:
Output:
Method 2 (using another string & for loop):
code:
Output:
above the code, each character is picked from the end & picked characters stored in reverseword variable.
Method 3 (using JavaScript array push() & pop() method)
Code:
Output:
Note:
In the above process, we implement the stack data structure using the array push () & pop () method