Javascript String reversed()
//Just like you can add methods to your own constructor, you can also add methods and properties to //built in classes in JavaScript like Arrays and Objects. //Add a reverse method to the String 'class' so that every instance of String can call reverse and reverse //itself.//w w w .ja v a2 s .c om String.prototype.reversed = function () { return this.split("").reverse().join(""); }; var iAmStr = "I am a string"; alert(String(iAmStr).reversed());