
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Convert number to reversed array of digits JavaScript
Let’s say, we have to write a function that takes in a number and returns an array of numbers with elements as the digits of the number but in reverse order. We will convert the number into a string, then split it to get an array of strings of digit, then we will convert the string into numbers, reverse the array and finally return it.
Following is our function that takes in a number to be reversed −
const reversifyNumber = (num) => { const numString = String(num); return numString.split("").map(el => { return +el; }).reverse(); };
Example
const reversifyNumber = (num) => { const numString = String(num); return numString.split("").map(el => { return +el; }).reverse(); }; console.log(reversifyNumber(1245)); console.log(reversifyNumber(123)); console.log(reversifyNumber(5645)); console.log(reversifyNumber(645));
Output
The output in the console will be −
[ 5, 4, 2, 1 ] [ 3, 2, 1 ] [ 5, 4, 6, 5 ] [ 5, 4, 6 ]
- Related Articles
- Convert number to a reversed array of digits in JavaScript
- Reversed array of digits from number using JavaScript
- Sorting digits of all the number of array - JavaScript
- The sum of digits of a two-digit number is 8. If 36 is added to the number then the digits reversed. Find the number.
- A two-digit number is 4 times the sum of its digits. If 18 is added to the number, the digits are reversed. Find the number.
- Difference between a number and its reversed number JavaScript
- Is the reversed number a prime number in JavaScript
- A number consists of two digits whose sum is five. When the digits are reversed, the number becomes greater by nine. Find the number.
- How to count digits of given number? JavaScript
- The sum of the digits of a 2-digit number is 8. If the digits are reversed, the new number increases by 18. Find the number.
- Convert array of object to array of array in JavaScript
- How to convert a number into an array in JavaScript?
- A two-digit number is 3 more than 4 times the sum of its digits. If 18 is added to the number, the digits are reversed. Find the number.
- Removing least number of elements to convert array into increasing sequence using JavaScript
- Finding product of Number digits in JavaScript

Advertisements