How to use String Reversal In Javascript
In this approach, we are using string reversal, converting a number to a string, reverse it using split(â).reverse().join(â), and convert back to a number.
Syntax:
let result = num1.toString().split('').reverse().join('');
Example: In this example, we are using the above-explained approach.
Javascript
let num1 = 123456789; let result = num1.toString().split( '' ).reverse().join( '' ); console.log(result); |
Output
987654321
JavaScript Program to Reverse Digits of a Number
In this article, we are going to learn about Reverse Number Programs in JavaScript. A reverse number in JavaScript involves reversing the digits of a given number. Itâs done by manipulating the digitâs order, resulting in the numberâs reversed form.
There are several methods that can be used to Reverse the Numbers by using JavaScript, which is listed below:
Table of Content
- Using String Reversal
- Using Array Reduce() Method
- Using String Iteration
- Using Recursion
Contact Us