Reversing a string in JavaScript

reverse() is a method of array instances. It won’t directly work on a string. You should first split the characters of the string into an array, reverse the array and then join back into a string:

var backway = oneway.split("").reverse().join("");


The method above is only safe for “regular” strings. Please see comment by Mathias Bynens below and also his answer for a safe reverse method.

Leave a Comment