I\'m trying to reverse an input string
var oneway = document.getElementById(\'input_field\').value();
var backway = oneway.reverse();
but f
The following technique (or similar) is commonly used to reverse a string in JavaScript:
// Don’t use this!
var naiveReverse = function(string) {
return string.split('').reverse().join('');
}
In fact, all the answers posted so far are a variation of this pattern. However, there are some problems with this solution. For example:
naiveReverse('foo