Reverse string in JavaScript

voted: 1
reverse string

In JavaScript String (unlike array) hasn't got native reverse function (at least by now). To reverse string we can use both String.prototype or "third party" function. To see full code and demo check out,js,output

/************** reverseString function **************/

function reverseString(str) {
  return str.split("").reverse().join("");

/****************** Edit prototype ******************/

// Make sure we won't owerwrite native code in the future
if (!('reverse' in String.prototype)) {
  String.prototype.reverse= function() {
    return this.split("").reverse().join("");
working url:,js,output
version: not entered
Leave a Comment:
Characters left:
No comments yet.