reverse string method code example

Example 1: javascript .split().reverse.join

"this is a test string".split("").reverse().join("");
//"gnirts tset a si siht"
//as a function
function reverseString(string){
return string.split("").reverse().join("");}
reverseString("test string");
//"gnirts tset"

Example 2: javascript reverse a string

function reverseString(s){
    return s.split("").reverse().join("");
}
reverseString("Hello");//"olleH"

Example 3: javascrip reverse text

//more compact way: 
"my example text".split("").reverse().join("");

Example 4: javscript .split().reverse.joni

"this is a test string".split("").reverse().join("");

Example 5: reverse words in a string javascript

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

Example 6: javascript reverse string

function reverseString(str) {
  if (str === "")
    return "";
  else
    return reverseString(str.substr(1)) + str.charAt(0);
}
reverseString("hello");

Tags:

Java Example