Reverse a string in JavaScript with example


Today you are going to learn how to reverse a string in JavaScript using reverse() function with an example script.

reverse() is a JavaScript function which alters the order of the elements in an array, so if you want to reverse a string, first you have to convert that string into an array.

Three JavaScript function you need to use for this:

1. split()
2. reverse()
3. join()

Here is the script:

So, basically split the string into array values, reverse the order and then join the array values, you have your result.

Here is an example usage of the above script:

And finally a demo link to test it:





Related Posts

One thought on “Reverse a string in JavaScript with example

Leave a Reply