Skip to content

Instantly share code, notes, and snippets.

@kosperera
Last active May 2, 2017 19:06
Show Gist options
  • Save kosperera/5c80840babc61ccc3ad7626415efb028 to your computer and use it in GitHub Desktop.
Save kosperera/5c80840babc61ccc3ad7626415efb028 to your computer and use it in GitHub Desktop.
Reverse a string value in JavaScript.
String.prototype.reverse = () => {
return this.split('').reverse().join('');
};
@kosperera
Copy link
Author

Usage

'ABC'.reverse();  // output: CBA
const name = 'KosalaNuwan';
name.reverse(); // output:  nawuNalasoK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment