Two ways reverse string.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | //with cycle (not recommended)
function StrReverse(str) {
var res = '';
for (var i = str.length - 1; i >= 0; --i)
res += str.charAt(i);
return(res);
}
alert(StrReverse(".gnirts a si sihT"));
//creating prototype
String.prototype.reverse = function() {
return this.split('').reverse().join('');
}
alert(new String(".gnirts a si sihT").reverse());
|