How to reverse a string using JavaScript?

Some different ways to reverse a string

  1. Array method

     const string = "Let's reverse this";
     return string.split("").reverse().join("");
    
  2. For-loop

     function reverse(str) {
         let final = "";
         for (let i = str.length - 1; i >= 0; i--) {
             final += str[i];
         }
         return final;
     }
    
  3. For-of-loop

     function reverse(str) {
         let reversed = "";
         for (let character of str) {
             reversed = character + reversed;
         }
    
         return reversed;
     }
    
  4. reduce()

     function reverse(str) {
         return str.split("").reduce((rev, char) => char + rev, "");
     }