How to reverse a string using JavaScript?
Some different ways to reverse a string
Array method
const string = "Let's reverse this"; return string.split("").reverse().join("");
For-loop
function reverse(str) { let final = ""; for (let i = str.length - 1; i >= 0; i--) { final += str[i]; } return final; }
For-of-loop
function reverse(str) { let reversed = ""; for (let character of str) { reversed = character + reversed; } return reversed; }
reduce()
function reverse(str) { return str.split("").reduce((rev, char) => char + rev, ""); }