| Viewed 95 times

How to Reverse the Number in JavaScript?


I need a function that takes an integer n and reverses it.

1 Answer
Mohammad Qandeel
Answered
13

Try this simple method it accepts a number the return a reversed

function rev(n) {
 let str = String(n);
 let str2 = str.split('');
 let str3 = str2.reverse().join('');
 
 return String(parseInt(str3)) ;
}

Example

rev(51) // "15"

 


Related Questions