This is one of oldest methods for reversing a text or string value. Its clean and does the job.
👉 More examples, and some different approach.
Reverse an Array using while loop
Although, we are talking about strings here, you can apply the above method on an array and reverse its values. For example,
The result however is different from the 1st example. Since its an array, its reverses the word, not the characters.
A More modern approach
Contrary to the above examples, especially the first example, this approach uses built-in functions, but it’s useful.
So, using these method, we’ll first reverse the string and then join it again to the string.
In-addtion, you can use ES6 to make it a one-liner.
const rev = [...s_word].reverse().join('');
👉 See the three dots within the square brackets […]. It’s a Spread Operator. It splits the string. Check this out.