- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Reversed array of digits from number using JavaScript
Problem
We are required to write a JavaScript function that takes in a number. Our function should first reverse the number and then split the reversed number into digits and return that splitted array of digits.
Input
const num = 1234567;
Output
const output = [7, 6, 5, 4, 3, 2, 1];
Because the reverse number is 7654321
Example
Following is the code −
const num = 1234567; const reverseAndSplit = (num = 1) => { const numStr = String(num); const arr = numStr.split(''); arr.reverse(); return arr.map(el => { return Number(el); }); }; console.log(reverseAndSplit(num));
Output
[7, 6, 5, 4, 3, 2, 1]
- Related Articles
- Convert number to reversed array of digits JavaScript
- Convert number to a reversed array of digits in JavaScript
- Sorting digits of all the number of array - JavaScript
- A two-digit number is 4 more than 6 times the sum of its digits. If 18 is subtracted from the number, the digits are reversed. Find the number.
- 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.
- 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.
- 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.
- Finding the only out of sequence number from an array using JavaScript
- Adding digits of a number using more than 2 methods JavaScript
- Changing second half of string number digits to zero using JavaScript
- Rearranging digits to form the greatest number using JavaScript
- 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.
- Separating digits of a number in JavaScript

Advertisements