Reverse a string
String.split("") splits the string into array of characters. Observe that we passed an empty string as argument to split() method.
Array.reverse() reverse the array of characters.
Array.join("") joins the array of characters into a string. Again, observe that we have passed an empty string to join() method. Empty string is used as delimiter between the items of the array while joining.
All these methods can be joining together via chaining mechanism. The string
str can be reversed using the following expression.
1. Given a string in
str. Reverse the string
let str = 'Hello World'; let output = str.split("").reverse().join(""); console.log(output);