by @kodeazy
JavaScript How to reverse a String with Single line statement?
- To reverse a string first we divide them using
split()
function. - Later we reverse the array of string by using
reverse()
function. - Then we join them using
join()
function. - Below is the sample example of reversing a string.
var name="John";
console.log(name.split("").reverse().join(""));
Output:
nhoj