Reversing a string challenge has been one of the oldest code challeges! Let’s see how can we do it in JS.
Using Array Methods:
Steps to follow:
- Split the string to
chararrays. - Reverse the
chararray. - At last
jointhe array to a string.
The same thing happens in the following code section:
1 | const stringToReverse = 'ashkeys'; |
With ES6 spread operator
It is possible to reduce one line from the above code using ES6 syntax! ^_^
1 | const stringToReverse = 'ashkeys'; |